htaccess 重定向某些网址的问题

发布于 2024-11-07 21:16:07 字数 611 浏览 0 评论 0原文

我有一堆遵循这种格式的 .htaccess 规则

RewriteCond %{HTTP_HOST} ^www.lazygamer\.co.za$ [NC]
RewriteRule ^(.*)$ http://www.lazygamer.net/$1 [R=301,L]

现在我需要放入一个新规则以在我的 URL 中包含一个类别字符串并获得此代码

RewriteRule ^/([^/]+)/$ /category/$1/ [R]

但由于某种原因它没有被解雇,有人可以告诉我如何更改上面的字符串以进一步匹配规则..所以我在执行规则之前检查某些条件?

仅当网址格式为 http://www.lazygamer.net/ 时,我才需要触发此规则post-name/ 而不是当 url 的格式为 http://www.lazygamer.net/category/post-name/

I have a bunch of .htaccess rules that follow this format

RewriteCond %{HTTP_HOST} ^www.lazygamer\.co.za$ [NC]
RewriteRule ^(.*)$ http://www.lazygamer.net/$1 [R=301,L]

Now I need to put in a new rule to include a category string in my URL and was given this code

RewriteRule ^/([^/]+)/$ /category/$1/ [R]

But it's not being fired for some reason, can someone please show me how to change the above string to match the rule further up.. so I check for some condition before executing the rule?

I only need this rule to fire if the url is in the format http://www.lazygamer.net/post-name/ and not when the url is in the format http://www.lazygamer.net/category/post-name/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最舍不得你 2024-11-14 21:16:08

我的 htaccess 文件现在看起来像这样并解决了问题

RewriteCond %{HTTP_HOST} !^images.lazygamer\.net$ [NC]
RewriteCond %{REQUEST_URI} !^/(wp-content|wp-admin|wp-includes|fixed|contact-details|advertise|about|category|submission|images|ps3|xbox-360|wii|other-news|video).*$
RewriteCond %{REQUEST_URI} !^\/$
RewriteRule ^(.*)$ http://www.lazygamer.net/fixed/$1 [R=301,L]

倒数第二行忽略了让我彻夜难眠的根文件夹......

My htaccess file now looks like this and solves the problem

RewriteCond %{HTTP_HOST} !^images.lazygamer\.net$ [NC]
RewriteCond %{REQUEST_URI} !^/(wp-content|wp-admin|wp-includes|fixed|contact-details|advertise|about|category|submission|images|ps3|xbox-360|wii|other-news|video).*$
RewriteCond %{REQUEST_URI} !^\/$
RewriteRule ^(.*)$ http://www.lazygamer.net/fixed/$1 [R=301,L]

The second last line ignore the root folder which kept me up all night...

や莫失莫忘 2024-11-14 21:16:07
RewriteCond %{REQUEST_URI} !^/category/.*$
RewriteRule ^([^/]+)/ /category/$1/ [R]
RewriteCond %{REQUEST_URI} !^/category/.*$
RewriteRule ^([^/]+)/ /category/$1/ [R]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文