简体   繁体   English

.htaccess 多个 url 变量

[英].htaccess multiple url variable

i want to write .htaccess to show url with common patters for example例如,我想编写 .htaccess 来显示带有常见模式的 url

1: abc.com/mypage   --> works fine 
2: abc.com/mypage/page/1  --> works fine 
3: abc.com/mypage/category/2   --> works fine 
4: abc.com/mypage/page/1/category/2   --> not works fine

so below is my .htaccess code所以下面是我的 .htaccess 代码

RewriteRule mypage/page/([^/]*) /?p=main_page&page=$1 [L]
RewriteRule mypage/category/([^/]*) /?p=main_page&cid=$1 [L]
RewriteRule mypage/page/([^/]*)/category/([^/]*) /?p=main_page&page=$1&cid=$2 [L]
RewriteRule mypage /?p=main_page [L]

how can we fix it please guide way to fix it我们如何修复它请指导修复它的方法

You have a typo but more importantly you are missing anchors in your regex.你有一个错字,但更重要的是你在你的正则表达式中缺少锚点。 You can use:您可以使用:

RewriteEngine On

RewriteRule ^mypage/page/([^/]+)/?$ ?p=main_page&page=$1 [L,QSA]
RewriteRule ^mypage/categroy/([^/]+)/?$ ?p=main_page&cid=$1 [L,QSA]
RewriteRule ^mypage/page/([^/]+)/category/([^/]+)/?$ ?p=main_page&page=$1&cid=$2 [L,QSA]
RewriteRule ^mypage/?$ ?p=main_page [L,QSA]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM