Search code examples
.htaccess

Redirecting query string for any search query for all URLs


I want to ask if it is possible to redirect

example.com/something?query=hell

to

example.com/something/hell

with the help of htaccess. I want to do it for all query i pass with GET method. Does anyone has any idea??


Solution

  • You can do this with the following rule in your htaccess

    RewriteEngine On
    
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/]+)/?$ /something?query=$1 [L]
    

    With the rule above you can just type example.com/foobar into your browser to access the page at example.com/something?query=foobar .