change script links using .htaccess

Discussion in 'PHP' started by KhaledBawz, Jul 31, 2013.

  1. #1
    Hello,

    I'm working on script, and want to set links to be as following:

    www.mysite.com/sign-up.php
    to
    www.mysite.com/sign-up

    I found this code and works for me.

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.+)$ $1.php [L,QSA] 
    
    Code (markup):
    BUT if I add a slash at the end of link, ex: www.mysite.com/sign-up/

    it shows me this error

    Internal Server Error
     
    The server encountered an internal error or misconfiguration and was unable to complete your request.
     
    Please contact the server administrator at admin@example.com to inform them of the time this error occurred, and the actions you performed just before this error.
     
    More information about this error may be available in the server error log.
    Code (markup):
    Q2- if the user try to access any php extension, I want him to redirect to same link without extension

    EX: www.mysite.com/sign-up.php
    to
    www.mysite.com/sign-up
    Thank you
     
    KhaledBawz, Jul 31, 2013 IP
  2. sorindsd

    sorindsd Well-Known Member

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    118
    #2
    Replace last line with
    RewriteRule ^(.*?)/?$ /$1.php [L]
     
    sorindsd, Jul 31, 2013 IP
  3. KhaledBawz

    KhaledBawz Greenhorn

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #3
    I replaced so my .htaccess looks like

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*?)/?$ /$1.php [L]
    
    Code (markup):
    but now all links doesn't work

    shows me file not found
     
    KhaledBawz, Aug 1, 2013 IP
  4. KhaledBawz

    KhaledBawz Greenhorn

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #4
    any one can help please?
     
    KhaledBawz, Aug 1, 2013 IP
  5. EmmanuelFlossie

    EmmanuelFlossie Active Member

    Messages:
    159
    Likes Received:
    11
    Best Answers:
    2
    Trophy Points:
    65
    #5
    if you add
    
    RewriteRule ^(.*)/$ $1 [R=301,L]
    
    Code (markup):
    It should remove all trailing slashes
     
    EmmanuelFlossie, Aug 1, 2013 IP
  6. KhaledBawz

    KhaledBawz Greenhorn

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #6
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.+)$ $1.php [L,QSA]
     
    RewriteRule ^(.*)/$ $1 [R=301,L]
    
    Code (markup):
    thanks but same problem :(
     
    KhaledBawz, Aug 1, 2013 IP