场合
我正在使用Zend框架,因此尝试按地址调用文件夹以惨败告终,我们收到错误:'指定的控制器无效'。我需要在单独的文件夹中连接其他论坛到应用程序。我更改.htaccess文件如下:
RewriteRule ^forum(.*)$ forum$1 [L]
并且有一段时间它很好,直到我意识到页面存在于两个域中的两个版本(php识别域[.pl / .co.uk]并选择语言)。所以我决定将论坛分开作为两个单独的模块(例如,波兰版论坛的文件夹将是:forum_pl,而对于英国,它将是:forum_uk - 两个不同的论坛)
有什么问题?
需要重写.htaccess文件才能像这样工作:
IF: www.domena.pl/forum
那么:从文件夹/ forum_pl
打开脚本IF: 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):
修改
我的上一个解决方案:
#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文件夹中拨打电话。
答案 0 :(得分: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]
如果您需要以不同的方式行动,请告诉我