删除.php扩展名的mod_rewrite会产生404错误 [英] mod_rewrite for removing .php extension is producing 404 error
问题描述
我已经查了一下,并为此尝试了3或4个答案,但它们对我不起作用.
我有dev.mydomain.com/pw/
,并且我希望dev.mydomain.com/pw/builder
重定向到dev.mydomain.com/pw/builder.php
等.
我尝试了几种解决方案,包括:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
来自:此处和:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
来自:此处
以及:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ $1.php [L]
我从其他项目中得到的
我还尝试将RewriteBase
应用于各种操作,例如/
和/pw/
无效.
明显我在做错/不做吗?
将此规则放在/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]
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?
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]
这篇关于删除.php扩展名的mod_rewrite会产生404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!