I’d like to remove path without query string after last slash on url.
For example, there is a url:
https://www.example.com/example.php/fakepath/fakepath2/fakepath3?id=123
I want to add a rewrite rule in .htaccess
file, and redirect origin url to this url:
https://www.example.com/example.php?id=123
Becasue I found this issue:
This is a correct url: http://www.twhappy.com/index.php?action=blog&category=6
If I add slash after index.php
, the url will be http://www.twhappy.com/index.php/?action=blog&category=6
If I add fake path after index.php
:
http://www.twhappy.com/index.php/?action=blog&category=6
http://www.twhappy.com/index.php/fakepath/?action=blog&category=6
http://www.twhappy.com/index.php/fakepath/fakepath2/fakepath3/?action=blog&category=6
These url can be visit after I added fake path.
So, I want a rewrite rule to redirect them to correct url.
Is there have any idea for this case?
Thanks you so much.
2
Answers
Please try:
UPDATED ANSWER
Here’s a
RedirectMatch
rule frommod_alias
that should strip anyPATH_INFO
from.php
files. This should perform the redirect you’re afterOld answer(s) below
You certainly don’t need
mod_rewrite
for this. Instead, enableAcceptPathInfo
, egThen, requests for
/example.php/fakepath/fakepath2/fakepath3?id=123
will resolve toexample.php
withproducing
Alternatively, if you don’t want to support URLs with
PATH_INFO
, you can turn it off withthen requests for URLs that contain
PATH_INFO
will result in a 404.