2012-10-13 55 views
1

我已經在我的public_html.So我的鏈接文件夾「雜誌」是這樣的:mod_rewrite的禁用舊鏈接

site/journals/index.php/journal1site/journals/index.php/journal2等(journal1,journal2只是illustration.It可能是技術,藝術等。 )

我有(在Jon的幫助下).htaccess使site/journals/index.php/journal1顯示爲site/index.php/journal1

但我仍然能夠訪問/查看site/journals/index.php/journal1

我想要禁用site/journals/index.php/journal1並且只有site/index.php/journal1應該是可見的。請讓我知道我該怎麼做。

請查閱this瞭解更多信息。

這裏是根現有的.htaccess(/)文件夾

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{REQUEST_URI} !^/sunder 
RewriteRule ^index\.php(.*)$ /sunder/index.php$1? [L] 
</IfModule> 

回答

0

我想禁用網站/雜誌/ index.php文件/ journal1,只有網站/的index.php/journal1應該visible.Please讓我知道我該怎麼做。

由於您想要禁用對舊URL的訪問(雖然仍在內部重寫它們),但您需要與實際請求進行匹配,而不僅僅是URI。如果您匹配URI並進行重定向,則重定向將在內部重寫,這將與其他規則匹配並再次重定向,導致瀏覽器抱怨該頁面未正確重定向。

嘗試增加這些規則權下,你已經有規則的RewriteEngine On(你的問題):

RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /sunder/([^\ ]+) 
RewriteRule^/%2 [L,R=301] 

這在實際請求的東西,開頭只被應用/sunder/,它將瀏覽器重定向到移除它的URL。

0

約翰給你是不正確的規則。讓我們看看:

您需要的是一個規則,將example.com/index.php/journal1之類的URL重寫爲指向/journals/index.php/journal1。因此,您必須注意不要過度匹配和重寫。

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    RewriteRule ^journals/(.*)$ http://example.com/$1 [R=301,L] 

    RewriteRule ^index\.php/(.*)$ /journals/index.php/$1 [L] 
</IfModule> 

重寫URL的例子:

example.com/index.php/journal2 => /home/bane/htdocs/journals/index.php/journal2 

example.com/index.php/foo/bar => /home/bane/htdocs/journals/index.php/foo/bar 
+0

它不僅僅是journal1,journal2-那是一個插圖。在journals/index.php後面,我可能會放上不同的名字 - 比如技術,藝術等等。 – MBanerjee

+0

然後,你應該花點時間改進你的問題,難道你不知道嗎?認爲? – aefxx

+0

不過,我已經爲你更新了我的答案。 – aefxx