I’m developing a web site using php.
And I want to use first directory name of URL as parameter for php.
I have the following rewrite rule:
RewriteRule ^([a-z][a-z])/(.*)$ xyz/$2?first-dir=$1 [L]
When I access http://example.com/aa/b/,
/xyz/b/index.php is executed with parameter first-dir=aa.
And URL in address bar of broweser is http://example.com/aa/b/ (same as input URL).
But when I access http://example.com/aa/b (without tailing /),
URL in address bar become http://example.com/xyz/b/?first-dir=aa.
I don’t want to show this rewrited URL to users.
Why is this happening?
How to fix this problem?
This is mod_dir and
DirectorySlashinterfering with your URI. When Apache sees that your URI is pointing to a directory but is missing the trailing slash, it will 301 redirect the client to the same URI with the trailing slash. Your rule is being applied, the mod_dir sees that/aa/bis a directory so it redirects the browser to/aa/b/. You’ll just need to check for the trailing slash in your rul: