redirect url exact match with htaccess not redirect if query string or anything after index.php
Redirect This Page: https://example.com/demo/index.php
To Page: https://example.com/ (home page)
But Do Not redirect: https://example.com/demo/index.php/*
Do NOT redirect: https://example.com/demo/index.php/password
Do NOT redirect https://example.com/demo/index.php?m=page
not redirect if any other combination
only redirect https://example.com/demo/index.php to https://example.com/
this script not working
RewriteEngine On
RewriteBase /
RewriteRule ^demo/index.php /demo/index.php?m=page[L,NC,END]
RewriteRule ^demo/index.php$ https://example.com/ [L,R=301]
3
Answers
If you only want to redirect that exact URL, without a query string then you need to reverse your existing rules and include an additional condition that checks that the QUERY_STRING is empty. The
RewriteRule
only matches against the URL-path, which excludes the query string.You are also missing a space before the flags argument in the first rule.
For example:
You don’t need
L
andEND
.Test with 302, and change to 301 only once you have confirmed it works OK. To avoid caching issues.
You may use these rules in site root .htaccess:
This was created by htaccess redirect generator I use very often.
Maybe “?” sign is redundant because of empty query string match.
Not sure, but You also can try to add
in case You can’t log in. All together: