skip to Main Content

I have a htaccess that rewrites to /login if conditions aren’t met.
It’s working fine for urls without query_string.

However I have no clue how to include /reset?query_string to accepted conditions. And want to exclude /reset

/reset?6tdsBMxpeeJEDUvYzwKmLzIusLYLjgMtIj

RewriteEngine On
RewriteBase /index.php

RewriteCond %{REQUEST_URI} !^/login$
RewriteCond %{REQUEST_URI} !^/forgotten$

RewriteRule ^([^.]+)$ /login [R=301,L,QSD]
RewriteRule ^(/)?$ /login [R=301,L]
RewriteRule ^([^.]+)$ $1.php [NC,L]

2

Answers


  1. With your shown samples and attempts, please try following htaccess rules file. Make sure to clear your browser cache before testing your URLs.

    Also I am making use of apache’s variable named THE_REQUEST by which we can handle both uri as well as query string.

    RewriteEngine ON
    RewriteBase /
    ##Rules for handling rest uri without query string.
    RewriteCond %{QUERY_STRING} ^$ 
    RewriteRule ^reset/?$ /login? [R=301,L,NC]
    
    ##Rules for reset with uri and query string.
    RewriteCond %{THE_REQUEST} s/reset?S+s [NC]
    RewriteRule ^ /reset? [R=301,NC]
    
    ##Rule for login page's backend rewrite.
    RewriteRule ^login/?$ login.php [QSA,NC,L]
    
    ##Rule for forgotten page's backend rewrite.
    RewriteRule ^forgotten/?$ forgotten.php [QSA,NC,L]
    
    ##Rules for non-existing pages should be served with index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [QSA,L]
    
    Login or Signup to reply.
  2. Here is a modified version of your .htaccess that excludes /reset?query:

    RewriteEngine On
    
    # /reset with query string
    RewriteCond %{QUERY_STRING} .
    RewriteRule ^(reset)/?$ $1.php [L,NC]
    
    RewriteCond %{REQUEST_URI} !^/(forgotten|login)$ [NC]
    RewriteRule ^([^.]*)$ /login [R=301,L,QSD]
    
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^([^.]+)$ $1.php [L]
    

    Make sure to test it after clearing your browser cache.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search