如何使用htaccess文件重定向不包含某些特定字符的URL?

时间:2015-10-30 07:48:58

标签: .htaccess url-rewriting url-redirection

假设我有一些这样的网址:

http://mydomaindotcom/abc/123-link.html

http://mydomaindotcom/abc/page/page-link.html

现在,我想将以下所有网址重定向:http://mydomaindotcom/ otherstring /123-link.html至http://mydomaindotcom/ abc / 123-link。 HTML

http://mydomaindotcom/ 另一个人 /page/page-link.html到http://mydomaindotcom/ abc /page/page-link.html

这意味着URL上的第一个段必须是[abc],否则,重定向到[abc] -beginning。

我该怎么做?

1 个答案:

答案 0 :(得分:2)

试试这个:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/abc/ [NC]
RewriteRule ^[^/]+/(.*)$ /abc/$1 [R=301,L,NC,QSA]
相关问题