I need to 301 redirect homepage
https://example.com/
to
https://example.com/category/news
But I have a newsletter that uses this URL after submit:
https://example.com.pl/?na=s
So after basic 301 redirection, newsletter submit link also redirects to https://example.com/category/news
How to avoid it?
I don't know how you are currently issuing the redirect, but in order to target the query string (in order to exclude that particular query string) then you'll need to use mod_rewrite.
For example:
RewriteEngine On
RewriteCond %{QUERY_STRING} !=na=s
RewriteRule ^$ /category/news [QSD,R=301,L]
The above redirects the homepage (ie. an empty URL-path), but specifically excludes the URL with the exact query string na=s
.
The QSD
flag discards any other query string that might have been on the initial request.
You will need to clear your browser cache before testing (since the erroneous 301 permanent redirect will have been cached by the browser). Test first with a 302 (temporary) redirect to avoid caching issues.
So after basic 301 redirection, newsletter submit link also redirects to
https://example.com/category/news
Although, ordinarily you would expect it to have redirected to https://example.com/category/news?na=s
, unless you had taken explicit measures to remove the query string from the redirect response.
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.