How to use RewriteRule url in 301 redirect

My current url structure:

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

      

Now I want to use a forward slash instead of an underscore, for example:

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

      

How can I redirect my old url to the new url?

I tried like this:

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

      

does not work.

+3


source to share


2 answers


In your rule, Redirect

you are using regex pattern in both source and destination url, besides, Redirect

it doesn't even accept regex.

You can do it like this using all the rules mod_rewrite

:



RewriteEngine On
RewriteBase /site/

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

      

+1


source


Try below also,



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]

      

+1


source







All Articles