2

I am very new to this stuff. I have a website with these RewriteCond/RewriteRule directives.

Options All -Indexes

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?page=$1 [QSA,L]

So far everything works on my website but I have a small issue. I will try to explain it.

  • https://example.com/login [Shows the login page]

  • https://example.com/asdasdasd [Shows the 404 not found page]

  • https://example.com/login/asdasdasd [Shows the login page too but it should show 404 not found page]

  • https://example.com/login%F0%9F%91%88%F0%9F%91%88%F0%9F%91%88 [Shows the login page too but it should show 404 not found page]

and I would like that every Query parameter will be removed.

If I open https://example.com/login?fbclid=IwAR2w6Ff that it redirects back to https://example.com/login

1 Answer 1

1

It would seem "the problem" is in your PHP code, not .htaccess as you seem to suggest.

RewriteRule ^(.+)$ index.php?page=$1 [QSA,L]

All requests are rewritten to index.php (your "front-controller") which then routes your URLs. It is this PHP script that determines whether /login or /login/asdasdasd, etc. resolve to a valid page on your site. This has nothing to do with Apache or your .htaccess file.

Aside: If there was a physical file at /login.php and MultiViews was enabled then this could be a different matter. However, it does not appear that MultiViews is enabled (ie. Options All -Indexes) so this does not seem to apply, even if login.php does exist as a physical file.

and i would like that every Query parameter will be removed.

if i open https://example.com/login?fbclid=IwAR2w6Ff that it redirects back to https://example.com/login

However, this you can do in .htaccess. At the top of your .htaccess file:

RewriteCond %{QUERY_STRING} .
RewriteRule ^(login)$ /$1 [QSD,R=301,L]

To remove the query string from any URL, not just /login then change the above RewriteRule to read:

RewriteRule (.*) /$1 [QSD,R=301,L]

Test with 302 (temporary) redirects first to avoid caching issues.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.