I have the following rewrite setup:
RewriteEngine on
RewriteRule ^(.*)/$ $1.php
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^(\w+)\.php$ /$1 [R=301]
RewriteRule ^(\w+)/?$ /$1.php
I'm trying to any page under my /admin
subdirectory (ie /admin/index.php
, /admin/users.php
, etc...) default to /admin/
.
I thought I could add the following:
RewriteRule ^admin/(\w+)\.php$ /admin/ [R=301]
After my existing 301 rewrite rule, but it's just creating a loop.
It's been a while since I wrote these rules, so I barely remember my mod rewrites and how I created them. (Not my strong suit.) Suggestions on how to fix this?
Thanks!
This should be your complete .htaccess:
RewriteEngine on
RewriteRule ^(admin)/[^.]+\.php$ /admin/ [NC,L,R=301]
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]
您应该使用:
RewriteRule ^(\w+)/admin/(\w+)\.php$ http://yourdomain/admin/ [R=301]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.