0

我想通过 htaccess 文件从 url 中删除 .php 。例如 home.php 到 home 我在 htaccess 文件中使用以下重写规则。

    RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]

我还想将登录名指定为索引。我怎样才能改变它。

4

2 回答 2

2

这是您可以用来隐藏 .php 扩展名的代码:

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

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L,NC]
于 2012-05-22T21:39:11.657 回答
0
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
# Replace html with your file extension, eg: php, htm, asp

在 URL 的末尾添加斜杠(例如:http://www.example.com/about-us/转至http://www.example.com/about-us.html

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/$ $1.html 

# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
于 2012-05-22T21:37:45.120 回答