2014-11-03 44 views
0

代碼的.htaccess錯誤很難發現...

<IfModule mod_rewrite.c> 
# Domain re-direction 
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^stackexchange\.net$ [OR] 
RewriteCond %{HTTP_HOST} ^www\.stackexchange\.net$ 
RewriteRule ^/?$ "https\:\/\/www\.stackexchange\.org\/「 [R=301] 
# 
#Support page re-direction 
RewriteCond %{REQUEST_URI} ^thesupport/?$ [NC] 
RewriteRule ^thesupport/?$ https\:\/\/www\.stackexchange\.org\/support\/ [R=301] 
# 
#Privacy page re-direction 
RewriteCond %{REQUEST_URI} ^privacy/?$ [NC] 
RewriteRule ^privacy/?$ https\:\/\/www\.stackexchange\.org\/privacy\/ [R=301,L] 
</ifModule> 

問題

  • 301重定向從 stackexchange.net stackexchange.org工作
  • 301重定向從 stackexchange.net/thesupport stackexchange.org/support不工作(總是給人一種404頁)問題,即使%{REQUEST_URI}替換或者

沒有區別:

%{THE_REQUEST} 
%{REQUEST_FILENAME} 
%{REMOTE_URI} 

我已經已經超過http://code.tutsplus.com/tutorials/an-in-depth-guide-to-mod_rewrite-for-apache--net-6708,但似乎無法找到錯誤來自哪裏。

任何有關我的艙口蓋代碼可能出錯的想法。

謝謝。

回答

0

問題是在這種情況下:

RewriteCond %{REQUEST_URI} ^thesupport/?$ [NC] 

由於REQUEST_URI比賽用斜線一個URI。所以,你糾正的條件應該是:

RewriteCond %{REQUEST_URI} ^/thesupport/?$ [NC] 

但是看着你的規則,你甚至都不需要一個條件,可以在RewriteRule處理這本身。

<IfModule mod_rewrite.c> 
# Domain re-direction 
RewriteEngine On 

RewriteCond %{HTTP_HOST} ^(www\.)?stackexchange\.net$ 
RewriteRule ^/?$ https://www.stackexchange.org [R=301,L] 

# 
#Support page re-direction 
RewriteRule ^thesupport/?$ https://www.stackexchange.org/support/ [R=301,L] 

# 
#Privacy page re-direction 
RewriteRule ^privacy/?$ https://www.stackexchange.org/privacy/ [R=301,L] 
</ifModule> 
+0

嗨,@anubhava會嘗試你的建議,並給予反饋。謝謝 – Sysuser 2014-11-03 10:23:15

+0

嗨@anubhava ...像以前一樣的問題...問題依然存在,甚至有清除所有緩存和CDN – Sysuser 2014-11-03 14:05:56

+0

它不是一個真正的目錄它是一個WordPress內的靜態頁面。 ... – Sysuser 2014-11-03 14:36:37

0

解決(@anubhava)如下:
- 用來重定向代碼由@anubhava
的建議 - 重定向代碼被轉移到.htaccess文件的頂部,它涉及的WordPress重寫規則之前。
- RewriteBase也添加到代碼中。

<IfModule mod_rewrite.c> 
# Domain re-direction 
RewriteEngine On 
ReWriteBase/
RewriteCond %{HTTP_HOST} ^(www\.)?stackexchange\.net$ 
RewriteRule ^/?$ https://www.stackexchange.org [R=301,L] 

# 
#Support page re-direction 
RewriteRule ^thesupport/?$ https://www.stackexchange.org/support/ [R=301,L] 

# 
#Privacy page re-direction 
RewriteRule ^privacy/?$ https://www.stackexchange.org/privacy/ [R=301,L] 
</ifModule> 

. 
. 
. 

# BEGIN WordPress