mvc powered by slash based urls => muweb.com/controller/param1/param2
how to rewrite muweb.com/controller/?item=45 to muweb.com/controller/45 or even to muweb.com/controller/item45 ?
As with most questions of this type, it is not clear what you want to change. That is, it is unclear what the user should enter in the address bar and what should be after the redirection. Therefore, we consider both options for redirection using the .htaccess file.
Option 1.1.
The source address is muweb.com/controller/?item=45 , the address after the redirection is muweb.com/controller/45 .
RewriteEngine On RewriteBase / RewriteCond %{QUERY_STRING} item=(\d+) RewriteRule ^(controller)$ $1/%1? [L,R] Option 1.2.
The source address is muweb.com/controller/?item=45 , the address after the redirection is muweb.com/controller/item45 .
RewriteEngine On RewriteBase / RewriteCond %{QUERY_STRING} item=(\d+) RewriteRule ^(controller)$ $1/item%1? [L,R] Option 2.1.
The source address is muweb.com/controller/45 , the address after the redirection is muweb.com/controller/?item=45 .
RewriteEngine On RewriteBase / RewriteRule ^(controller)/(\d+)/?$ $1?item=$2 [L,R,QSA] Option 2.2.
The source address is muweb.com/controller/item45 , the address after the redirection is muweb.com/controller/?item=45 .
RewriteEngine On RewriteBase / RewriteRule ^(controller)/(item)(\d+)/?$ $1?$2=$3 [L,R,QSA] Option 2.3.
The source address is muweb.com/controller/item45 , or muweb.com/controller/45 , the address after the redirection is muweb.com/controller/?item=45 .
RewriteEngine On RewriteBase / RewriteRule ^(controller)/(\d+)/?$ $1?item=$2 [L,R,QSA] RewriteRule ^(controller)/(item)(\d+)/?$ $1?$2=$3 [L,R,QSA] Source: https://ru.stackoverflow.com/questions/491775/
All Articles