1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Simple Mod_Rewrite help please

Discussion in 'Apache' started by alphacooler, Nov 9, 2005.

  1. #1
    Simple question,

    What 'exactly' do I put into my .htaccess file in order to get URL1 to change to URL2.

    URL1: www.sitename.com/file.php
    URL2: www.sitename.com/file.html

    NOTE: I don't want to do this sitewide. I'm just after the code to do this on a single page.

    And then I just need to go back and change all my internal links so they point to the "file.html" right?

    Thanks so very much

    -Complete n00b.
     
    alphacooler, Nov 9, 2005 IP
  2. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #2
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^file\.html$ file.php [L]

    Then change links to .html.
     
    Nintendo, Nov 9, 2005 IP
  3. alphacooler

    alphacooler Peon

    Messages:
    70
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3

    So in order to multiple rewrites in the same .htaccess file do I just repeat the line "RewriteRule ^file\.html$ file.php [L]" (inserting the URL that I want to change from PHP to HTML) or do I need to turn the Engine on and do all that every time?

    Thanks so much Nintendo!
     
    alphacooler, Nov 9, 2005 IP
  4. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #4
    Only add

    RewriteRule ^file\.html$ file.php [L]

    for each file.

    If it's every file like that

    RewriteRule ^([^.]+)\.html$ $1.php [L]
     
    Nintendo, Nov 9, 2005 IP
  5. alphacooler

    alphacooler Peon

    Messages:
    70
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Anything else I should do special for the root besides changing index.php to index.html? (www.sitename.com)

    Also what about duplicate content issues? Should all of the PHP extensions be 301'ed to the HTML versions? If so, what is the correct syntax there?

    Thanks so much Nintendo!
     
    alphacooler, Nov 9, 2005 IP
  6. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #6
    You only want one URL for each page!!

    You don't have to change the actual file name at all, only the links.

    Do you currently link to the php URLs?
     
    Nintendo, Nov 9, 2005 IP
  7. alphacooler

    alphacooler Peon

    Messages:
    70
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7

    The site isn't live yet and so I have freedom to change anything.

    So I just changed all of my links to go to the HTML pages instead of the PHP pages. BUT the PHP pages can still be accessed if somebody typed them in or linked to them.

    If a say a competitor linked to my PHP pages instead of HTML they could create a duplicate content issue for me. So what should be done?
     
    alphacooler, Nov 9, 2005 IP
  8. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #8
    If you only link to .html URLs, no one will ever know you have .php files, unless you use forms that generate php URLs.
     
    Nintendo, Nov 9, 2005 IP
  9. alphacooler

    alphacooler Peon

    Messages:
    70
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I do have one php "rating" script that I wrote. Users enter form info and then I display it, but I am having trouble with this and the mod_rewrite. Anything special that needs to be done when using the mod_rewrite and php forms?
     
    alphacooler, Nov 12, 2005 IP
  10. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #10
    Search engines don't use forms/click buttons, so it'll never find those URLs from there, and I have yet to ever hear of a competator of any site hunting for and linking to a non mod_rewrite URL. They got more importent stuff to do.
     
    Nintendo, Nov 12, 2005 IP