我在重定向某些頁面時遇到了問題。我重寫規則看起來像(例如):使用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