Php htaccess在子文件夹中使用多个参数重写url
我需要重写以下url:Php htaccess在子文件夹中使用多个参数重写url,php,.htaccess,mod-rewrite,url-rewriting,Php,.htaccess,Mod Rewrite,Url Rewriting,我需要重写以下url: http://localhost/homemarket/products/C1/C2/ 到 我尝试在stackoverflow上搜索,发现了类似的重写规则,但我面临以下问题: 这些规则与我的removing.php规则冲突(将.php添加到我的子类别查询中) 若子类别被删除,它将重定向到404页 如果没有提供,它将再次重定向到404页面 以下是我尝试过的: # Do not remove this line, otherwise mod_rewrite rules
http://localhost/homemarket/products/C1/C2/
到
我尝试在stackoverflow上搜索,发现了类似的重写规则,但我面临以下问题:
- 这些规则与我的removing.php规则冲突(将
添加到我的子类别查询中).php
- 若子类别被删除,它将重定向到404页
- 如果没有提供,它将再次重定向到404页面
# 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 404 /homemarket/error.php?404
ErrorDocument 500 /homemarket/error.php?500
#Remove extensions
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ /homemarket/buyers/$1.php [NC,L]
RewriteRule ^products/([^/]*)/([^/]*)/?$ /homemarket/buyers/products.php?category=$1&sub_category=$2 [NC,L]
DirectoryIndex index.php
#不要删除此行,否则mod#u重写规则将停止工作
选项+多视图
重新启动发动机
重写基/
#阻止查看.htaccess文件
命令允许,拒绝
全盘否定
#阻止目录列表
选项所有-索引
#错误文档
ErrorDocument 404/homemarket/error.php?404
ErrorDocument 500/homemarket/error.php?500
#删除扩展名
重写cond%{REQUEST_FILENAME}-F
重写规则^([^\.]+)$/homemarket/buyer/$1.php[NC,L]
重写规则^products/([^/]*)/([^/]*)/?$/homemarket/PUTERS/products.php?类别=1美元,子类别=2美元[NC,L]
DirectoryIndex.php
您的第一条规则与两个URI都匹配,您需要排除规则中的斜杠,以便它不会与其他规则冲突:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+)$ /homemarket/buyers/$1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+)$ /homemarket/buyers/$1.php [NC,L]