.htaccess mod_rewrite plays with variables

I want my site urls to look like

http://example.com/place/info?var=info&morevars=ifneeded

      

Place and information are also variables, but they have a fixed name, after which they will change. EDIT This is the url I am trying to rewrite

http://example.com/test.php?place=test&action=info&var=info&morevars=ifneeded

      

This is what I still have

RewriteEngine on

RewriteRule ^([A-Za-z0-9-]+)/?$ test.php?place=$1 [NC]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ test.php?place=$1&action=$2 [NC]

      

I think there is a way to do this with {QUERY_STRING}, but I cannot get it to work with only 500 errors or it makes no difference.

0


a source to share


2 answers


You have set a flag QSA

that automatically adds the original requested request to the new one:



RewriteEngine on
RewriteRule ^([A-Za-z0-9-]+)/?$ test.php?place=$1 [NC,QSA]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ test.php?place=$1&action=$2 [NC,QSA]

      

+1


a source


You are missing the first /



RewriteEngine on

RewriteRule ^/([A-Za-z0-9-]+)/ test2.php?place=$1 [NC]
RewriteRule ^/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/ test2.php?place=$1&action=$2 [NC]

      

0


a source







All Articles