Apache .htaccess将旧域/文件夹重定向到新域/其他文件夹
我在httpd.config中使用它,它可以工作:Apache .htaccess将旧域/文件夹重定向到新域/其他文件夹,apache,.htaccess,mod-rewrite,redirect,Apache,.htaccess,Mod Rewrite,Redirect,我在httpd.config中使用它,它可以工作: <VirtualHost *:80> ServerName olddomain.com ServerAlias www.olddomain.com Redirect permanent /FolderName/Filename_with_underscores.html http://newdomain.com/some-folder-with-dashes/?lang=fr Redirect permanent /FolderNa
<VirtualHost *:80>
ServerName olddomain.com
ServerAlias www.olddomain.com
Redirect permanent /FolderName/Filename_with_underscores.html http://newdomain.com/some-folder-with-dashes/?lang=fr
Redirect permanent /FolderName/Other_filename.html http://newdomain.com/some-other-folder/?lang=fr
Redirect permanent / http://newdomain.com/
</Virtualhost>
Thnx您可以在根目录中使用
。htaccess
:
RewriteEngine on
# All rules only for olddomain.com
RewriteCond %{HTTP_HOST} !^(www\.)?olddomain\.com$ [NC]
RewriteRule ^ - [L]
RewriteRule ^FolderName/Filename_with_underscores\.html$ http://newdomain.com/some-folder-with-dashes/?lang=fr [NC,R=301,L]
RewriteRule ^FolderName/Other_filename\.html$ http://newdomain.com/some-other-folder/?lang=fr [NC,R=301,L]
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
谢谢,我会尽快试一试的!您好,很遗憾,您的解决方案不起作用。这与我的一次试验非常相似。当我键入一个url时,网站上说“找不到页面”,就像我尝试了你的转义解决方案一样——eitherOk不起作用。但这是我的.htaccess中存在的,因为其他域有更多的规则。。。(简单重定向)。这可能是您的实际链接或其他规则的位置有问题。因为这里的规则没有问题。谢谢,我会做进一步的调查。
RewriteEngine on
# All rules only for olddomain.com
RewriteCond %{HTTP_HOST} !^(www\.)?olddomain\.com$ [NC]
RewriteRule ^ - [L]
RewriteRule ^FolderName/Filename_with_underscores\.html$ http://newdomain.com/some-folder-with-dashes/?lang=fr [NC,R=301,L]
RewriteRule ^FolderName/Other_filename\.html$ http://newdomain.com/some-other-folder/?lang=fr [NC,R=301,L]
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]