2011-12-01 70 views
0

對於以下內容,RewriteRule的等效物是什麼?RewriteRule Equivalent

Redirect permanent /a.html http://www.example.com/b/ 

注意a.html也駐留在同一個域例如www.example.com

我發現使用Redirect指令有點麻煩,因爲"destination" URL cannot use a relative path

+0

請注意* a.html *假定位於同一個服務器上,即* http://www.example.com/*。 – moey

+0

但「http:// www.example.com/b/」不是*相對URL? – symcbean

+0

@symcbean:* http:// www.example.com/b/*是一個完全合格的URL。我正在尋找一種使用相對路徑的解決方案,例如'/ B /'。 – moey

回答

0

如果您想要將a.html重定向到相同的域,但是/ b /目錄例如http://www.anydomain.com/a.htmlhttp://www.anydomain.com/b/請將以下內容添加到您的域根目錄中的.htaccess文件中。

RewriteEngine On 
RewriteBase/

#reirect a.html to /b/ 
RewriteRule ^a.html$ b/ [L,R=301] 
+0

謝謝,@Ulrich!對不起,我之前沒有指定'a.html'在同一個域中;遵循示例,它在* www.example.com *上。 – moey

+0

這太棒了。在.htaccess級別指定重寫規則在HTTP和HTTPS上都可以使用;如果它在虛擬主機上,則需要執行以下操作:http://stackoverflow.com/q/8759906/583539 – moey