I want to modify the URL on my server using .htaccess
but I'm facing some issues.
In my previous question I described all the modifications I wanted. I want add some new rules along side the previous rules.
RewriteEngine On
# matches /site/ or /site/index.php or
# /a/site/index.php or /b/site/index.php
# captures a/ or b/ or an empty string in %1
# redirects to /a/ or /b/ or /
RewriteCond %{THE_REQUEST} \s/+([ab]/|)site/(?:index\.php)?[?\s] [NC]
RewriteRule ^ /%1 [L,R=302,NE]
# matches a/ or b/ or empty (landing page)
# rewrites to a/site/index.php or b/site/index.php or site/index.php
RewriteRule ^([ab]/)?$ $1site/index.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
New Rule #1:
https://example.com/site/index.php
(already does)
https://example.com/site/index
(does not)
https://example.com/site/
(already does)should get converted to short url.
https://example.com/
New Rule #2:
https://example.com/a/site/index.php
(already does)
https://example.com/a/site/index
(does not)
https://example.com/a/site/
(already does)should get converted to short url.
https://example.com/a/
New Rule #3:
https://example.com/site/any.php
(does not)
https://example.com/site/any
(does not)should get converted to short url.
https://example.com/any/
New Rule #4:
https://example.com/any/
(does not)should load full url without expanding.
https://example.com/site/any.php
Note that: The any.php
is dynamic, means it's a ([\w]+).php
and I don't know to write .htaccess
, any help would be much appreciated.