Removing trailing question mark with htaccess

前端 未结 2 1533
悲&欢浪女
悲&欢浪女 2020-12-03 20:22

Can someone help me understand this code?

# Remove trailing ?
RewriteCond %{THE_REQUEST} ? HTTP [NC] 
RewriteRule .? /%{REQUEST_URI}? [R=301,L]
2条回答
  •  隐瞒了意图╮
    2020-12-03 20:55

    1) Case 1: removing question mark

    http://example.com/page/subpage/?YOURSTRING=blabla
    

    to redirect to

    http://example.com/page/subpage/
    

    then in the beggining of .htaccess, insert:

    
    RewriteEngine On
    RewriteCond %{QUERY_STRING} YOURSTRING=(.*)
    RewriteRule ^(.*)$ /$1? [R=301,L]
    
    
    # if wordpres isnot installed in root folder, then edit the fourth line to this
    # RewriteRule ^(.*)$ /YOUR-WORDPRESS-DIRECTORY/$1? [R=301,L]
    

    2) Case 2: redirection from question mark to another link

    http://example.com/index.php?YOURSTRING=blabla&id=44
    

    to redirect to

    http://example.com/page/subpage/
    

    Use:

    
    RewriteEngine On
    RewriteCond %{QUERY_STRING} YOURSTRING=blabla&id=44
    RewriteRule ^(.*)$ http://example.com/page/subpage/? [R=301,L]
    
    

提交回复
热议问题