如何为单个页面重写插件域的URL?

时间:2012-08-08 03:08:48

标签: regex .htaccess redirect

我在stonycreekgallery.com.au上有一个WordPress网站,其中有redpeppergallery.com.au作为插件域(更正:'停放域名,抱歉)。

我希望访问者主要以stonycreekgallery.com.au的身份浏览网站,但每当他们访问单页http://stonycreekgallery.com.au/red-pepper-gallery/时,我都希望将网址重写为redpeppergallery.com.au。

我找到了similar question(未答复),并尝试了以下内容:

RewriteCond %{HTTP_HOST} ^(www.)?redpeppergallery.com.au$ [NC]
RewriteCond %{REQUEST_URI} !^/red-pepper-gallery/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /red-pepper-gallery/ [L]
RewriteCond %{HTTP_HOST} ^(www.)?redpeppergallery.com.au$ [NC] 
RewriteRule ^(/)?$ red-pepper-gallery/ [L] 

这些规则目前在域名中有效。

对我有什么指示?! TIA,蒂姆


编辑:一些澄清......

  • 只有一个网站,在wordpress网站上运行
  • redpeppergallery的链接在WordPress中设置为指向redpeppergallery.com.au
  • redpeppergallery是一个停放的域/域别名(上面我错误地将其称为插件)
  • redpeppergallery.com.au应该直接转到http://stonycreekgallery.com.au/red-pepper-gallery/

以下是完成工作的一半 - 将redpeppergallery直接转到正确的页面:

RewriteCond %{HTTP_HOST} ^(www.)?redpeppergallery.com.au$ [NC]
RewriteCond %{REQUEST_URI} !^/red-pepper-gallery/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://stonycreekgallery.com.au/red-pepper-gallery/ [L]

任务的第二部分是:当在页面上stonycreekgallerycom.au/red-pepper-gallery/(仅此页面):将URL显示为redpeppergallery.com.au ..这是我不确定的......我从那以后尝试过:

RewriteCond   %{REQUEST_FILENAME}   ^stonycreekgallery.com.au/red-pepper-gallery/?$         [NC]
RewriteRule   http://redpeppergallery.com.au/  [R=301]

我期待迟早会打一个循环,但它还没有发生:)我试过的最后一个片段的变化没有效果......

1 个答案:

答案 0 :(得分:0)

尝试将此内容放入 stonycreekgallery.com.au 域的文档根目录中的htaccess文件中:

Redirect 301 /red-pepper-gallery http://redpeppergallery.com.au/

如果您不想重定向,但希望浏览器的网址地址栏保留在 stonycreekgallery.com.au ,那么它将取决于您的配置。

如果两个域都停放在同一个文档根目录,意味着例如http://stonycreekgallery.com.au/http://redpeppergallery.com.au/都是从目录/something/www/root提供的,那么您可以在文档根目录中执行此操作htaccess文件:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?stonycreekgallery.com.au$ [NC]
RewriteRule ^red-pepper-gallery/(.*) /$1 [L]

否则,如果一个文档根位于另一个文档根目录中,例如,http://stonycreekgallery.com.au/从目录/something/www/root提供,但http://redpeppergallery.com.au/从目录/something/www/root/gallery提供,则你这样做:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?stonycreekgallery.com.au$ [NC]
RewriteRule ^red-pepper-gallery/(.*) /gallery/$1 [L]

如果这两个域是从完全独立的文档根目录提供的,那么您需要使用[P]标志,但只有在加载了mod_proxy时才会起作用:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?stonycreekgallery.com.au$ [NC]
RewriteRule ^red-pepper-gallery/(.*) http://redpeppergallery.com.au/$1 [P,L]