删除.php扩展名的mod_rewrite会产生404错误 [英] mod_rewrite for removing .php extension is producing 404 error

查看:61
本文介绍了删除.php扩展名的mod_rewrite会产生404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经查了一下,并为此尝试了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆