问题
I've looked up and tried 3 or 4 answers on SO for this and they are not working for me.
I have dev.mydomain.com/pw/
and I want dev.mydomain.com/pw/builder
to redirect to dev.mydomain.com/pw/builder.php
etc.
I have tried several solutions including:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
from: here and:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
from: here
as well as:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ $1.php [L]
that I have from other projects.
I have also tried manipulating the RewriteBase
to various things, like /
and /pw/
to no effect.
Anything obvious I'm doing wrong/not doing?
回答1:
Place this rule in /pw/.htaccess
:
RewriteEngine On
RewriteBase /pw/
RewriteCond %{THE_REQUEST} /(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/pw/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
来源:https://stackoverflow.com/questions/25337282/mod-rewrite-for-removing-php-extension-is-producing-404-error