1

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 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

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]

8 Comments

I tried it, it's nog working. Changed the code a bit to give more inside.
It breaks the conditions
Still breaking. I think on \s. Only login works everthing else 'File not found'. I can use a hack if page is /reset and has no query then redirect in php. However I want to catch it in the first stage in htaccess. appreciate the help mate
@DataConnect, so what I understood is, is uri is like http://localhost:8080/ OR http://localhost:8080/login OR http://localhost:8080/forgotten OR http://loalhost:80/reset?blabla then it should go to /login these rules handle these, let me know if anything else is needed.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.