简体   繁体   中英

htaccess redirect is not working with [R=301,L]

I did the changes to my web site to change the dynamic url to SEO friendly url. I have added the following rewrite rule to my .htaccess file for 301 redirection.

RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+business\.php\?cat=([^\s&]+)&subcat=([^\s&]+) [NC]
RewriteRule ^Software&Tools/%1/%2? [R=301,L]
RewriteRule ^Software&Tools/([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/?$ business.php?cat=$1&subcat=$2 [QSA,L,NC]

but when i typed seo friendly url in the browser it is redirecting back to the old url.

anybody can help me ?

You should not use R=301 back to original URI.

Have your rule like this:

RewriteEngine on
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+abc\.php\?products=([^\s&]+) [NC]
RewriteRule ^ products/%1? [R=301,L]

RewriteRule ^products/([\w-]+)/?$ abc.php?products=$1 [QSA,L,NC]

EDIT: Based on your edited question:

RewriteCond %{THE_REQUEST} \s/+business\.php\?cat=([^\s&]+)&subcat=([^\s&]+) [NC]
RewriteRule ^ Software&Tools/%1/%2? [R=301,L]
RewriteRule ^Software&Tools/([\w-]+)/([\w-]+)/?$ business.php?cat=$1&subcat=$2 [QSA,L,NC]

EDIT FORMAT

RewriteEngine on
RewriteCond %{HTTP_HOST} ^jaring\.poskopilkadapolri\.web\.id$ [OR]
RewriteCond %{HTTP_HOST} ^www\.jaring\.poskopilkadapolri\.web\.id$
RewriteRule ^/?$ "https\:\/\/jaring\.poskopilkadapolri\.web\.id\/module\/home\/" [R=301,L]

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM