因此,我正在将我的站点从一个子域“移动”到根域上的一个子文件夹中,在这个过程中,我不得不改变一些子目录结构。这使得重定向对于像我这样几乎没有htaccess知识的人来说有点困难。
一些结构对于架构中更深层的东西是相同的(它本质上是一个目录网站),但有些东西需要移动。以下是我到目前为止创建的内容:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com/for-sale$
RewriteRule ^(.*)$ http://www.example.com/property-for-sale/search$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com/for-sale-details$
RewriteRule ^(.*)$ http://www.example.com/property-for-sale/details$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com/buyer-registration
RewriteRule ^(.*)$ http://www.example.com/property-for-sale/buyer-registration [R=301,L]
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com/advertise-with-us
RewriteRule ^(.*)$ http://www.example.com/property-for-sale/advertise-with-us [R=301,L]
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com/favourites
RewriteRule ^(.*)$ http://www.example.com/property-for-sale/favourites [R=301,L]
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com/saved-searches
RewriteRule ^(.*)$ http://www.example.com/property-for-sale/saved-searches [R=301,L]
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com/system$
RewriteRule ^(.*)$ http://www.example.com/property-for-sale/system$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com
RewriteRule ^(.*)$ http://www.example.com/property-for-sale/ [R=301,L]我想要发生的一个例子是
http://subdomain.example.com/for-sale-details/35141_xml_bvi0009154/gensac-gironde 重定向到
http://www.example.com/property-for-sale/details/35141_xml_bvi0009154/gensac-gironde 诸若此类。
从本质上讲,上述代码末尾没有$的重定向是独立的页面,在此之后没有更多的子目录。任何在末尾带有$的内容都意味着还有更多的目录层,但是在这之后的任何内容都应该保留在新URL的末尾。
任何帮助都将不胜感激!是的,当涉及到这类事情时,我是一个完全的新手,所以请对我友好点:)
发布于 2013-09-04 03:36:59
%{HTTP_HOST}变量是来自请求的“”报头,其中只有包含主机名,而不像/for-sale那样包含路径信息。因此,您只与此匹配,并且您的任何规则都不会起作用,因为您正在尝试与URI路径进行匹配。
因此,您的所有规则都需要如下所示:
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC]
RewriteRule ^for-sale/(.*)$ /property-for-sale/search/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC]
RewriteRule ^for-sale-details/(.*)$ /property-for-sale/details/$1 [R=301,L]等。
https://stackoverflow.com/questions/18595534
复制相似问题