Using // to make search-friendly URLs

Discussion in 'Apache' started by pr0fess0r, Nov 12, 2006.

  1. #1
    Hi all
    I followed the tutorial here:

    http://www.shadow-fox.net/site/tutorial/45-Create-Dynamic-URLs-With-Mod-Rewrite-and-PHP-Functions

    to create a rewrite rule so that
    http://blah/index.php?id=7&page=4

    could be written

    http://blah/index//id/7/page/4/

    for search engine friendliness, but it's not working.
    I wanted to use the double slash system because my site has all sorts of pages with parameters currently passed by the querystring, and I didnt want to have to write a rule for each, so by using the // I could ensure everything after that was a variable/value pair

    I have a Windows server running Apache, with the following .htaccess file in http://blah/foo/:

    RewriteEngine on
    RewriteRule (.*)//(.*) $1.php?parameters=$2

    But using the URL

    http://blah/foo/index//id/10/

    I get a 404 error.

    If I use

    RewriteEngine On
    RewriteRule index/(.*) index.php?parameters=$1

    Then

    http://blah/foo/index/id/10/

    works fine. Can anyone help me out with the correct expression to get // working?

    many thanks

    Lucas
     
    pr0fess0r, Nov 12, 2006 IP
  2. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #2
    Um, you don't want two //'s in a row.

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^index/id/([^.]+)/page/([^.]+)/$ index.php?id=$1&page=$2 [L]
     
    Nintendo, Nov 13, 2006 IP
  3. pr0fess0r

    pr0fess0r Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    OK, I was keen to have a generic way to deal wiht lots of different page names and parameters, ie
    index.php?id=7
    detail.php?id=4&page=3
    products.php?category=7
    etc
    So I would need a rule for each one?

    cheers
     
    pr0fess0r, Nov 13, 2006 IP
  4. dilute

    dilute Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yes, most probably since there are different numbers of parameters.
     
    dilute, Nov 13, 2006 IP
  5. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #5
    You'll need a line for each script.
     
    Nintendo, Nov 13, 2006 IP