7

情况

我正在使用 Zend 框架,因此尝试按地址调用文件夹以失败告终,我们收到错误:“指定的控制器无效”。我需要将其他论坛连接到单独文件夹中的应用程序。我将 .htaccess 文件更改如下:

RewriteRule ^forum(.*)$ forum$1 [L]

有一段时间很好,直到我意识到该页面存在于两个域中的两个版本中(php 识别域 [.pl/.co.uk] 并选择语言)。所以我决定将论坛分成两个单独的模块(例如,波兰版论坛的文件夹将是:forum_pl,而对于英国,它将是:forum_uk - 两个不同的论坛)

有什么问题?

它需要重写 .htaccess 文件才能像这样工作:

如果: www.domena.pl/forum

然后:从文件夹 /forum_pl 打开脚本

如果: www.domain.co.uk/forum

然后:从文件夹 /forum_uk 打开脚本。

最糟糕的是,当我尝试修复 .htaccess 文件添加 RewriteCond 时,第一个重定向不再正常工作,即使返回到原始(如上所示)版本也是如此。

如果我没有找到之前给出的答案,请帮助我并抱歉。

编辑:

第一个工作解决方案

RewriteRule ^forum_pl(.*)$ forum_pl$1 [L]
RewriteRule ^forum_uk(.*)$ forum_uk$1 [L]
RewriteCond %{HTTP_HOST} ^www.domena.pl(.*) [NC]
RewriteRule ^forum(.*)$ forum_pl$1 [L]
RewriteCond %{HTTP_HOST} ^www.domain.co.uk(.*) [NC]
RewriteRule ^forum(.*)$ forum_uk$1 [L]

看起来它想要工作,但是需要解决的问题是(TODO):

  1. 当您输入: www.domain.pl/forum 时,它会将您带到 www.domain.pl/forum_pl/ 但如果您输入: www.domain.pl/forum/ 它会将您带到 www.domain.pl/forum/ (阅读来自forum_pl)。如何使其在第一种情况下与第二种情况相同。

编辑:

我的最后一个解决方案:

#FORUM
#PL
RewriteCond %{REQUEST_URI} ^/forum$ [NC]
RewriteRule ^(.*)$ forum/ [R=301,L]

RewriteRule ^forum_pl(.*)$ forum_pl$1 [L]

RewriteCond %{REQUEST_URI} ^/forum_pl(.*)$ [NC]
RewriteRule ^(.*)$ http://www.domena.pl/forum/ [R=301,L] #Dosen't work properly (?)

RewriteCond %{HTTP_HOST} ^www.domena.pl(.*) [NC]
RewriteCond %{REQUEST_URI} ^/forum(/?)$ [NC]
RewriteRule ^forum[^/](.*)$ forum_pl/$1 #Dosen't work properly, but without it crash!
RewriteRule ^forum(.*)$ forum_pl$1 [L]
#UK
RewriteCond %{REQUEST_URI} ^/forum_uk(.*)$ [NC]
RewriteRule ^(.*)$ http://www.domain.co.uk/forum/ [R=301,L] #Dosen't work properly (?)

RewriteCond %{HTTP_HOST} ^www.domain.co.uk(.*) [NC]
RewriteCond %{REQUEST_URI} ^/forum(/?)$ [NC]
RewriteRule ^forum[^/](.*)$ forum_uk/$1 #Dosen't work properly, but without it crash!
RewriteRule ^forum(.*)$ forum_uk$1 [L]

最终的工作版本:

RewriteRule ^forum_pl(.*)$ forum_pl$1 [L]
RewriteRule ^forum_uk(.*)$ forum_uk$1 [L]

RewriteRule ^forum_pl(.*)$ http://www.domena.pl/forum$1 [R=301,L] # Not working!
RewriteRule ^forum_uk(.*)$ http://www.domain.co.uk/forum$1 [R=301,L] # Not working!

# Normalize URL first:
RewriteRule ^forum$ forum/ [R=301,L]

# redirect to polish version of web under forum_pl if on .pl TLD and
#  request is made to /forum/ (already normalized)
RewriteCond %{HTTP_HOST} =www.domena.pl [NC]
RewriteRule ^forum(.*)$ forum_pl$1 [L]

# redirect to english version of web under forum_en in on .uk TLD and
#  request is made to /forum/
RewriteCond %{HTTP_HOST} =www.domain.co.uk [NC]
RewriteRule ^forum(.*)$ forum_uk$1 [L]

很遗憾,您可以手动从浏览器的 forum_uk 和 forum_pl 文件夹中调用。

4

1 回答 1

1

不确定我是否通过一些演变正确地解决了你的长问题:-)让我们试试这个:

# Normalize URL first:
RewriteRule ^forum$ forum/ [R=301,L]

# redirect to polish version of web under forum_pl if on .pl TLD and
#  request is made to /forum/ (already normalized)
RewriteCond %{HTTP_HOST} =www.domena.pl [NC]
RewriteRule ^forum/(.*)$ http://www.domena.pl/forum_pl/$1 [R=301,L]

# redirect to english version of web under forum_en in on .uk TLD and
#  request is made to /forum/
RewriteCond %{HTTP_HOST} =www.domain.co.uk [NC]
RewriteRule ^forum/(.*)$ http://www.domain.co.uk/forum_uk/$1 [R=301,L]

如果您需要重写以采取不同的行动,请告诉我

于 2012-11-15T08:34:07.983 回答