從URL

2016-02-05 49 views
0
的末尾刪除TMPL =組分和打印= 1

我試圖重定向:從URL

www.domain.com/someword/xxxx-other-words?tmpl=component&print=1 

要:

www.domain.com/someword/xxxx-other-words 

這是我使用的.htaccess代碼:

RewriteCond %{QUERY_STRING} "?tmpl=component&print=1" [NC] 
RewriteRule (.*) /$1? [R=301,L] 

這是返回500 IS Error

+1

你設置了'RewriteEngine on'嗎? – 2016-02-05 11:15:17

+0

@noob我當然沒有 –

+0

你使用'apache'嗎? – 2016-02-05 11:17:52

回答

0

好像忘記啓用mod_rewrite的(你可以在/var/log/apache2/error.log檢查)或AllowOverride指令是不存在的。

我做(新鮮的debian /傑西):

# apt-get install apache2 
# a2enmod rewrite 
    add AllowOverride into /etc/apache2/sites-enabled/000-default.conf 
# systemctl restart apache2 

你的站點的配置應該有AllowOverride All內<目錄>,類似的東西

<VirtualHost *:80> 
     ServerAdmin [email protected] 
     DocumentRoot /var/www/html 

     <Directory "/var/www/html"> 
       AllowOverride All 
     </Directory> 

     ErrorLog ${APACHE_LOG_DIR}/error.log 
     CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost> 

和/ var/www/html等/.htaccess(默認網站)

RewriteEngine on 
RewriteCond %{QUERY_STRING} tmpl=component&print=1 [NC] 
RewriteRule (.*) /$1? [R=301,L] 

這對我有用。

0

嘗試使用重寫規則,如果你有Apache。

RewriteEngine on 
RewriteRule (.*)(\?tmpl=component&print=1) $1 [R=301,L] 

Regex101 Demo for replacement only.

+0

中工作得很好謝謝,我試過了,但沒有奏效。 –