从URL

2016-02-05 44 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

中工作得很好谢谢,我试过了,但没有奏效。 –