.htaccess rewrite URL with a question mark "?" only for 1 specific url

I already started the topic a few weeks ago. But I got a new problem, which is very similar to the old problem: .htaccess rewrite the URL with the question mark ""

My goal was this URL:

/mysite/component/users/?view=registration 

Rewrite this new URL:

 mysite/registration.html 

My current .htaccess got this code:

 RewriteBase /mysite RewriteCond %{QUERY_STRING} ^view=(.*)$ RewriteRule ^component/users/?$ %1.html? [R=301,L] 

He worked very well.

But then I noticed that this config applies to all URLs that start as follows:

 /mysite/component/users/?view= 

For example, this configuration also applies to a URL like this:

 /mysite/component/users/?view=remind 

This is what I don't want

I want this URL to be rewritten:

 localhost/mysite/component/users/?view=registration 
+5
source share
1 answer
 RewriteBase /mysite RewriteCond %{QUERY_STRING} ^view=(registration)$ [NC] RewriteRule ^component/users/$ %1.html? [R=301,L] 

If you want it to work only for registration , you can specify this instead of the catchall regular expression.

Also keep in mind that since you have global persistent redirects, you may need to clear your browser cache or use a different browser to see the changes instantly.

+5
source

Source: https://habr.com/ru/post/956015/


All Articles