How would I mod_rewrite my files so they do not show a .PHP extension in the url?

Discussion in 'Apache' started by Imozeb, May 21, 2010.

  1. Namjies

    Namjies Peon

    Messages:
    315
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #21
    
    RewriteCond %{THE_REQUEST} ^[A-Z]+\ [^.]+\.php\ HTTP/
    RewriteRule ^([^.]+)\.php$ /$1 [R=301,L]
    
    RewriteRule ^([^.]+)$ $1.php [L]
    
    Code (markup):
    should be working. It does on my server for one thing. And it's probably what Kidatum used.

    What else do you have on your .htaccess?
     
    Namjies, May 27, 2010 IP
  2. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #22
    This is what I have on my .htaccess file in my main directory.

    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^(www.)?foreverplaying.com$

    RewriteRule ^(/)?$ /script/index.php



    RewriteCond %{THE_REQUEST} ^[A-Z]+\ [^.]+\.php\ HTTP/
    RewriteRule ^([^.]+)\.php$ /$1 [R=301,L]

    RewriteRule ^([^.]+)$ $1.php [L]

    It's supposed to delete the .php extension without changing where the page is going to right? (going to the .php page)
     
    Imozeb, May 27, 2010 IP
  3. Namjies

    Namjies Peon

    Messages:
    315
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #23
    exactly what it should be doing. Wasn't there a

    Options +FollowSymlinks

    before that

    RewriteEngine On

    ?

    It's usually not needed if it's enabled on server, but depends on configuration. Else I have no clue for now.
     
    Namjies, May 27, 2010 IP
  4. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #24
    It does the same thing with or without the Options +FollowSymlinks

    It goes to the page if it has .php in it, but if I don't have the .php it gives a 404 error. I'm using godaddy.com hosting if that matters.
     
    Imozeb, May 27, 2010 IP
  5. Namjies

    Namjies Peon

    Messages:
    315
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #25
    If you're now getting 404, it must be the rewrite which cause problems.

    If you access a .php file, does it redirect to the url without the .php extension?

    Is there dots in your clean urls?
    like
    clean
    example.com/title.1
    and real url
    example.com/title.1.php
    ?

    Because both the redirect and rewrite ignores urls with dots in them, except for the dot in .php
     
    Namjies, May 29, 2010 IP
  6. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #26
    No, there are not dots or questions marks in my urls. When I type in my url with the .php it does not change the url in the address bar to the one without the .php extension.
     
    Imozeb, May 29, 2010 IP
  7. Namjies

    Namjies Peon

    Messages:
    315
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #27
    well that's strange. Maybe if I could play a bit with that file I could get something working with an alternative syntax.
     
    Namjies, May 31, 2010 IP
  8. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #28
    Try copying the .htaccess file into your script folder, I'm guessing there's a path issue here somewhere.
     
    tolra, Jun 1, 2010 IP