.htaccess 301重定向:访问新域名和查看旧域名的所有结构保持不变,只有新的url


.htaccess 301 redirect: access new domain and view old domain with all structure maintained, only with the new url

我想访问http://newdomain.co/并查看来自http://olddomain.com/shop/的所有内容,但url栏显示新域并保留所有旧结构。

电子商务平台为OpenCart。在位于/shop/文件夹下的。htaccess中,我目前有以下代码:

Options +FollowSymlinks
Options -Indexes
<FilesMatch "'.(tpl|ini|log)">
 Order deny,allow
 Deny from all
</FilesMatch>
RewriteEngine On
RewriteBase /shop/
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} !^(www'.|$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule sitemap.xml /index.php?route=feed/google_sitemap
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

我不习惯htaccess代码,所以请解释清楚:)

您需要使用mod_proxy来完成此操作。你不能使用mod_proxy,除非它被加载到你的apache服务器中。如果它已加载,您可以将其添加到newdomain的文档根目录下的htaccess文件中。公司举办:

RewriteEngine On
RewriteCond %{HTTP_HOST} newdomain'.co$ [NC]
RewriteRule ^(.*)$ http://olddomain.com/shop/$1 [L,P]

如果什么都没有发生,或者你被重定向到旧域名,那么你没有加载mod_proxy。

如果两个域都使用相同的文档根,那么你不需要使用mod_proxy,你只需要在文档根:

RewriteEngine On
RewriteCond %{HTTP_HOST} newdomain'.co$ [NC]
RewriteRule ^(.*)$ /shop/$1 [L]