Using .htaccess
from my previous question, I edited it to add a rewrite rule for rewriting /contact/
to /contact.php
and /xyz/contact/
to /contact.php?lang=xyz
. While the second one works, the first still looks for the actual directory which doesn't exist, returning 404
code. Both redirects to the nice URL variant work just like expected. Here is my .htaccess
settings for that:
# No directory listing, no multi views, follow symlinks
Options -Indexes -MultiViews +FollowSymLinks
# Redirects and rewrites allowed
RewriteEngine on
# ...
# Redirect direct requests for "contact.php?lang=xyz" to "/xyz/contact/"
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^lang=([a-z]{2,3})$
RewriteRule ^contact\.php$ /%1/contact/? [R=301,L]
# Redirect direct request for "contact.php" to "/contact/"
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^contact\.php$ /contact/? [R=301,L]
# Internally rewrite "/xyz/contact/" to "/contact.php?lang=xyz"
RewriteRule ^([a-z]{2,3})/contact/?$ /contact.php?lang=$1 [L]
# ...
# Internally rewrite "/contact/" to "/contact.php"
RewriteRule ^/contact/?$ /contact.php [L]