简体   繁体   中英

Redirect old dynamic url to a new pattern using htaccess

A normal link of my site may look like this

mydomain.com/categorylist/8/Special_Single_Songs.html

I'm planning to change the URL pattern to something like

mydomain.com/categorylist/8-Special-Single-Songs.html

How can I redirect the old URL pattern to the new one using .htaccess redirect rule?

My .htaccess Rewrite rule look like this

RewriteRule ^categorylist/([0-9]+)/([0-9a-z]+)/([0-9]+)/(.*)\.html$ /index.php?pid=$1&sort=$2&page=$3 [L]

Try this code

RewriteRule ^categorylist/([0-9]+)/([0-9a-z]+)/([0-9]+)/(.*).html$ /index.php?pid=$1&sort=$2&page=$3 [L]

RewriteRule ^categorylist/([0-9]+)\-([0-9a-z]+)/([0-9]+)/(.*).html$ /index.php?pid=$1&sort=$2&page=$3 [L]

try this & put it on top after RewriteEngine on

RewriteRule ^categorylist([^_]*)_([^_]*_.*).html$ $1-$2 [L,NE]
RewriteRule ^categorylist([^_]*)_([^_]*).html$ /$1-$2 [L,NE,R=301]

note : big number of underscores can be a problem

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