简体   繁体   中英

how to use RewriteRule URL in 301 redirect

My current url structure is:

RewriteRule ^([^/]*)_([^/]*).uz$    postview.php?url=$1&authorurl=$2 [L]

Now I want to use slash instead of underscore, like:

RewriteRule ^([^/]*)/([^/]*).uz$    postview.php?url=$1&authorurl=$2 [L]

How can I redirect my old url to new url?

I tried like this,

Redirect 301 ^([^/]*)_([^/]*).uz$ ^([^/]*)/([^/]*).uz$

not working.

In your Redirect rule you are using a regex pattern both in source and target URLs, besides Redirect doesn't even accept regular expressions.

You can do it like this using all mod_rewrite rules:

RewriteEngine On
RewriteBase /site/

RewriteRule ^([^_]*)_([^.]+\.uz)$ $1/$2 [L,NC,R=301,NE]
RewriteRule ^([^/]+)/([^.]+)\.uz$ postview.php?url=$1&authorurl=$2 [L,NC,QSA]

Try with below too,

RewriteEngine On
RewriteCond %{REQUEST_URI} ^([^/]+)_([^/]+).uz$
RewriteRule ^ %1/%2.uz [R=301,L]

RewriteCond %{REQUEST_URI} ^([^/]+)/([^/]+).uz$
RewriteRule ^ postview.php?url=%1&authorurl=%2 [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