2017-02-19 70 views
0

如果URL包含單詞「博客」,那麼下面的塊應在.htaccess的.htaccess如果URL中包含「博客」,然後執行規則

RewriteBase /blog/ 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /blog/index.php [L] 

執行我試着在加入RewriteCond %{REQUEST_URI} ^/blog頂部,但失敗。

PS:

我加

RewriteCond %{ENV:REDIRECT_rewritten} !=1 
RewriteCond %{QUERY_STRING} ^lang=([a-z]{2})$ [NC] 
RewriteRule ^([^/]*)$ /%1/$1? [R=301,L] 

RewriteCond %{REQUEST_URI} !^/(js)/ 
RewriteRule ^([a-z]{2})(?:/([^/]+))?$ $2?lang=$1 [NC,L,QSA,E=rewritten:1] 

這使得它如此比如當你去example.com/fr它就像example.com/index.php?lang=fr(除非它example.com/js...寫在規則)

+0

將你的最後一個移動到'/ blog/.htaccess'中(如果它不存在,就創建它) – anubhava

回答

1

無點將其添加到頂部。 RewriteConds僅適用於以下RewriteRule。你可以這樣說:

RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_URI} ^/blog(?:/|$) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /blog/index.php [L] 

我拿了第一RewriteBase行了,因爲它僅適用於相對換人,這你不用在這裏。

看起來這是設置在您的/blog/目錄中的.htaccess文件中,在這種情況下,我添加的東西無論如何都不需要。如果您將其移至根目錄,則需要更改第一行。根據你在同一個問題上的其他帖子猜測一下。

+0

嗨,現在當我去博客網址時,例如'example.com/blog/2017/01/18/some -blog-post /',它表示'在這個服務器上沒有找到請求的URL /example/blog/index.php。' –

+0

但是它之前使用RewriteBase規則工作。問題是它與我添加的其他規則無法很好地發揮作用,我只是更新了該帖子。 –

+0

RewriteBase不會引起問題,它根本就沒有做任何事情,這就是爲什麼我建議刪除它。什麼是'/ example/blog /',你必須進行另一次重寫或者進入其中。 – SuperDuperApps