【发布时间】:2016-06-28 04:40:13
【问题描述】:
我的基本要求是:
- 从所有网址中删除
.php扩展名。 - 将网址从
http://localhost/unsync/softwares/page_name/sub_category/重写为http://localhost/unsync/softwares.php?p=page_name&sub_cat=sub_category
以下是我的.htaccess代码:
# Do not remove this line, otherwise mod_rewrite rules will stop working
Options +MultiViews
RewriteEngine On
RewriteBase /
#Prevent viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
#Prevent directory listings
Options All -Indexes
#Error Documents
ErrorDocument 400 /unsync/error.php?code=400
ErrorDocument 401 /unsync/error.php?code=401
ErrorDocument 402 /unsync/error.php?code=402
ErrorDocument 403 /unsync/error.php?code=403
ErrorDocument 404 /unsync/error.php?code=404
ErrorDocument 500 /unsync/error.php?code=500
ErrorDocument 503 /unsync/error.php?code=503
#Remove extensions
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ /unsync/$1.php [NC,L]
RewriteRule softwares/(.*)/(.*)/$ /softwares.php?p=$1&sub_cat=$2 [L]
DirectoryIndex index.php
我面临的问题是,RewriteRule 失败。我的意思是,当我尝试访问 softwares/page_name/sub_category 时,它会抛出 404 错误。
注意:它可以正确删除
.php扩展名,并且可以正常处理普通页面。
【问题讨论】:
标签: php apache .htaccess mod-rewrite url-rewriting