简体   繁体   English

如何在301重定向中使用RewriteRule URL

[英]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. 在您的Redirect规则中,您在源URL和目标URL中都使用正则表达式模式,此外Redirect甚至不接受正则表达式。

You can do it like this using all mod_rewrite 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]

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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