2016-04-16 25 views
0

的htaccess的規則,能不能請你幫得到這個工作 -特定類型的URL

http://domain.com/gallery/category/another/slug 

http://domain.com/gallery/ 

如果URL中包含單詞gallery不管是什麼的一部分,剩下的就將始終發送請求到http://domain.com/gallery/

http://domain.com/gallery/category/another/slug -> will hit http://domain.com/gallery/ 
http://domain.com/gallery/another/slug -> will hit http://domain.com/gallery/ 
http://domain.com/gallery/more/more/slug -> will hit http://domain.com/gallery/ 

目前我的現有.htaccess看起來是這樣的 -

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /site/ 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /site/index.php [L] 
</IfModule> 
# END WordPress 

回答

0

如果你想每一個畫廊URL重寫到/gallery/你可以做

RewriteRule ^gallery/.* /gallery/ 

這將尋找任何URL在您的主機名,其路徑與(^)字開始gallery,接着是什麼(.*),並把它改寫爲/gallery/

您可以添加幾個標誌 - [L]如果要停止評估OTH呃規則,[NC]如果它不應區分大小寫。

如果您將此添加到一堆現有規則中,您可能需要使用該命令。

+0

感謝您的回答。你可以看到我目前的.htaccess文件。我在RewriteRule行之前添加了'RewriteRule^gallery /.*/gallery/[L]'。 /site/index.php [L]'它顯示對象未找到!如果我添加'RewriteRule^gallery /.*/site/gallery/[L]',它會顯示內部服務器錯誤。你有什麼建議嗎? – HADI

+0

是否存在?另外,'[L]'表示這應該是最後執行的規則。這可能是也可能不是你想要的。有關詳細信息,請參閱https://httpd.apache.org/docs/2.0/mod/mod_rewrite.html或https://httpd.apache.org/docs/2.0/misc/rewriteguide.html – Amanda

+0

yes domain.com/gallery exists ,我只想顯示domain.com/gallery頁面內容,如果用戶點擊domain.com/gallery或domain.com/gallery/more或domain.com/gallery/more/slug – HADI