2016-12-09 38 views
0

如何將Prestashop類別的Trailing Slash 301重定向僅使用(!)?Traling Slash重定向Prestashop類別

我有這個解決方案,但是這對所有URL都有效。

#Force trailing slash 
RewriteCond %{REQUEST_FILENAME} !-f 

RewriteCond %{REQUEST_URI} !(.*)/$ 

RewriteCond %{REQUEST_URI} !\.[^/]*$ 

RewriteRule ^(.*)$ /$1/ [L,R=301] 

我有這個重寫我的網址。

Categories : {rewrite}/ 
Product: {category:/}{rewrite}.html 

我需要這個了404錯誤,如果我使用一些類別無斜線:

http://shop.domain.com/category_example -> 404 error 

必須重定向到

http://shop.domain.com/category_example/

回答

0

在後臺去Preferences -> SEO & URLs並設置Route to category{id}-{rewrite:/}

這將使用尾部斜槓作爲類別,並將不帶斜槓的類別重定向到帶斜槓的正確URL。

+0

你好,這並不工作,因爲根類(指數-PHP)成爲404錯誤。我的網址也沒有ID:{rewrite}/ – redpillcoders

+0

@ user3221012如何在不使用{{id}'的情況下設置類別和產品路由? PrestaShop不允許沒有它的路由,至少不是從後臺設置。但是,如果您使用的是某個SEO模塊,那麼您可能會向開發人員詢問這一點。 – TheDrot

+0

它與Dispachter和Link.php重寫。這對於SEO廣告系列的友好網址很重要。 – redpillcoders

0

嘗試添加以下代碼到你的.htaccess文件:

# Various rewrite rules. 
    <IfModule mod_rewrite.c> 
    RewriteEngine on 

    #--------------- custom redirects ----------------- 
    #hard coded 
    RewriteRule ^this_is_hot_news/index\.html http://www.mysite/news [R=301,L] 

    RewriteRule (.*)/index\.html$ http://www.mysite.nl/$1 [R=301,L] 
    RewriteRule (.*)\.html$ http://www.mysite.nl/$1 [R=301,L] 

    RewriteRule (.*)/index\.php$ http://www.mysite.nl/$1 [R=301,L] 
    RewriteRule (.*)\.php$ http://www.mysite.nl/$1 [R=301,L] 

    #end custom redirects