skip to Main Content

this is my htaccess file :

<IfModule mod_rewrite.c>
        # Turn mod_rewrite on
        RewriteEngine On
        RewriteBase /
       
        RewriteRule ^getlastversion(.*)$ /lastversion.php$1 [R=301,NC,L,QSA]

        # this is temporary and should be removed 
        RewriteRule ^(.*)$ http://example.com?$1 [R=301,NC,L,QSA]
</IfModule>

browsing mysite.com/getlastversion redirect to example.com?lastversion.php(second rule),whereas i need it to be redirected to /lastversion.php(first rule)

2

Answers


  1. You may try this rule with a negative lookahead condition:

    RewriteEngine On
    RewriteBase /
           
    RewriteRule ^getlastversion(.*)$ /lastversion.php$1 [R=301,NC,L,QSA]
    
    # this is temporary and should be removed 
    RewriteRule ^(?!lastversion.php)(.*)$ http://example.com?$1 [R=301,NC,L]
    

    (?!lastversion.php) is negative lookahead that will skip this rule if we have /lastversion.php at the start of the URL.

    Make sure to test this rule after fully clearing your browser cache.

    Login or Signup to reply.
  2. Based on your shown samples, could you please try following. Please make sure to clear your cache before testing your URLs.

    RewriteEngine On
    RewriteBase /
           
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^getlastversion(.*)/?$ /lastversion.php$1 [R=301,NC,L,QSA]
    
    # this is temporary and should be removed 
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !lastversion.php [NC]
    RewriteRule ^(.*)$ http://example.com?$1 [R=301,NC,L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search