我尝试在为特定网页创建“漂亮网址”的同时删除.php
扩展程序。
我正在尝试将domain.com/dox?id=3
转换为domain.com/3
我的htaccess文件中的当前重写条件:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]*)\$ /dox?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# remove index
RewriteRule (.*)/index$ $1/ [R=301]
这会在domain.com/3
处产生错误,说明:
Not Found
The requested URL /3.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
但是,如果我在代码中添加任何扩展名,它就可以了。要解释我的意思,如果我将第四行更改为:
RewriteRule ^([^/]*)\.extension$ /dox?id=$1 [L]
然后可以在domain.com/dox?id=3
domain.com/3.extension
显然问题是这两个规则是冲突的,但不是一个htaccess高手,我无法弄明白
答案 0 :(得分:1)
试试这个:
RewriteRule ^([A-Za-z0-9-]+)/?$ /dox?id=$1 [L]
或者,如果id只是一个数字,那么这更合适:
RewriteRule ^([0-9]+)/?$ /dox?id=$1 [L]