1

我正在尝试进行两次 mod 重写。让我解释。


- 我需要一个重写,如果不存在文件或目录,则重定向到用户页面。| 我已经这样做了。 - 接下来,我想从.php文件中删除扩展名。

我已经完成了第一个,我只是不知道我该怎么做第二个?


我的代码已经:

RewriteEngine On


RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.*)$ users.php?name=$1 [QSA,L]

所以我需要的是,我只需要删除 .php 扩展名并保持当前的重写工作。

4

2 回答 2

1

这应该是您完整的 .htaccess:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

## redirect to a userpage
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ users.php?name=$1 [QSA,L]
于 2013-04-04T14:06:30.940 回答
0

删除 .php 扩展名:

RewriteEngine On
# turn on the mod_rewrite engine

RewriteCond %{REQUEST_FILENAME}.php -f
# IF the request filename with .php extension is a file which exists
RewriteCond %{REQUEST_URI} !/$
# AND the request is not for a directory
RewriteRule (.*) $1\.php [L]
# redirect to the php script with the requested filename

只需指出:

http://www.mysite.com/index

于 2013-04-04T01:41:07.053 回答