Sorry, this is probably a simple issue but I've read tons of tutorials and can't solve the issue. Here's the URL sample:
http://localhost:8106/privacy-policy/?lang=fr&dest=app
The .htaccess contents:
RewriteEngine on
RewriteRule ^privacy-policy/?lang=([a-z][a-z])&dest=app$ privacy-policy/$1 [NC,L]
When I visit the URL I don't get redirected. Any ideas?
Thanks
You can't match against the query string in a rule, you need to use the %{QUERY_STRING}
variable:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^lang=([a-z][a-z])&dest=app$
RewriteRule ^privacy-policy/$ privacy-policy/%1 [NC,L]
Note that the backreference needs to be %1
. If you need it to redirect the browser, you'll also need a R
flag in the square brackets.
Thanks Jon Lin for the leads on the query_string and %1 edit. It didn't end up working with a copy/paste of that code but this is finally what I ended up with and it is working:
RewriteCond %{REQUEST_URI} privacy-policy
RewriteCond %{QUERY_STRING} lang=(\w+)&dest=app
RewriteRule ^privacy-policy/$ /privacy-policy/%1? [R=301,L]
Thanks again for your help on this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.