我在重定向某些页面时遇到了问题。我重写规则看起来像(例如):使用Apache的RewriteRule进行301重定向(对于Joomla网站)
RewriteRule /index.php?option=com_content&view=article&id=47:article-keyword&catid=8:position$ article-keyword.html [R=301,L]
但它不工作,我试图一些不同的组合,但它仍然无所作为。 任何解决方案?
我在重定向某些页面时遇到了问题。我重写规则看起来像(例如):使用Apache的RewriteRule进行301重定向(对于Joomla网站)
RewriteRule /index.php?option=com_content&view=article&id=47:article-keyword&catid=8:position$ article-keyword.html [R=301,L]
但它不工作,我试图一些不同的组合,但它仍然无所作为。 任何解决方案?
更新:下面的RewriteRule不正确。请参阅2012年7月9日更新的详细信息
我读过的RewriteRules总是相对的,因此尝试:
RewriteRule ^index\.php\?option=com_content&view=article&id=47:article-keyword&catid=8:position$ article-keyword.html [R=301,L]`
这应该重定向到/index.php?option=com_content&view=article&id=47:article-keyword&catid=8:position
article-keyword.html
的^
标识开始的字符串。请参阅http://www.noupe.com/php/10-mod_rewrite-rules-you-should-know.html了解更多关于Apache RewriteRule的信息。
更新 - 2012-07-08
好,阅读Apache文档之后,重写规则不匹配的查询字符串。要匹配查询字符串中的数据,您需要使用RewriteCond
和%QUERY_STRING
变量。
成功!以下为我工作!
RewriteCond %{QUERY_STRING} option=com_content&view=article&id=47:article-keyword&catid=8:position
RewriteRule ^index\.php$ article-keyword.html? [R=301,L]
这重定向到http://site.domain.com/index.php?option=com_content&view=article&id=47:article-keyword&catid=8:position
http://site.domain.com/article-keyword.html
这仅重定向有问题的查询字符串请求的index.php。
感谢您的回复,但仍然没有重定向,我已经尝试过^在开始时,没有任何帮助。 – Kamil 2012-07-09 15:30:01
你在哪里放置这个RewriteRule?如果在.htaccess中,请发布整个.htaccess文件。 – HeatfanJohn 2012-07-09 15:30:56
我在RewriteEngine On语句和RewriteBase(也没有设置RewriteBase的情况下尝试)之后放置它。 – Kamil 2012-07-09 15:33:48
你可以添加一些文件,说明你正在努力完成什么?根据您发布的规则,您似乎想要更改非常特定的URL /index.php?option=com_content&view= article&id = 47:article-keyword&catid = 8:position $'到'article-keyword.html'如果是这种情况,这种重定向没有发生? – HeatfanJohn 2012-07-09 15:16:13
是的我有几个特定的链接,我想重定向 – Kamil 2012-07-09 15:27:47