.htaccess - remove query string

108 views Asked by At

Currently visitors see my website in this way: example.com/index.php?s=anyword+to+search

I would like to change to example.com/anyword+to+search

My current .htaccess:

Options -Indexes +FollowSymLinks    
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{THE_REQUEST} !/artist/ [NC]
RewriteRule ^(.*)$ artist/$1 [L,R]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f 

<IfModule mod_php5.c>  
    RewriteRule ^(.*)$ index.php/$1 [L]    
</IfModule>    

# the following is for rewritting under FastCGI
<IfModule !mod_php5.c>    
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

Does anyone know how?

2

There are 2 answers

3
Stuart Wagner On

Try something like this:

RewriteRule ^(.*)$ /index.php?s=$1 [L]
0
Amit Verma On

Try this rule to redirect query string to short url :

Options -Indexes +FollowSymLinks    
RewriteEngine On
RewriteBase /
#http to https   
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#Query string to short url
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/index\.php\?s=([^&\s]+) [NC]
RewriteRule ^ %1? [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?)/?$ index.php?s=$1 [QSA,B,NC,L]