繁体   English   中英

.htaccess中的不同重写规则

[英]Different rewrite rule in .htaccess

我的htaccess中已经有此重写规则

RewriteCond $1 !^(index\.php)
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?id_user=$1&page=$2 [L]

http://www.mydomain.com/index.php?id_user=user&page=news
http://www.mydomain.com/user/news.html

现在我有一个新闻详细信息和事件详细信息的问题。

对于具有这样的网址(仅用于页面新闻):

http://www.mydomain.com/user/details-news/category/title-news.html

这(仅用于页面事件)

http://www.mydomain.com/user/event/title-event.html

我可以在htaccess中插入新规则以获取这些规则,还是必须编辑实际规则?

我的网址在所有查询中都相同

index.php?id_user=user&page=details-news&category=category&title=title-news
or
index.php?id_user=user&page=event&title=title-event

任何帮助将不胜感激!

您的实际规则仅针对:

^([^/]*)/([^/]*)\.html$

网址。

这意味着只有一个/内部。 因此,您可以添加其他斜线更多的规则,而无需修改此实际现有规则。

唯一的问题是,如果要添加带有/的其他规则。 但这种情况并非如此。

您可以使用以下规则:

# skip further rules for files/directories
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/([^/.]+)\.html$ /index.php?id_user=$1&page=$2 [L,QSA]

RewriteRule ^([^/]+)/([^/]+)/([^/.]+)\.html$ /index.php?id_user=$1&page=$2&title=$3 [L,QSA]

RewriteRule ^([^/]+)/^([^/]+)/([^/]+)/([^/.]+)\.html$ /index.php?id_user=$1&page=$2&category=$3&title=$4 [L,QSA]

暂无
暂无

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

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