使用mod_rewrite 100%镜像另一个目录

时间:2014-04-20 23:07:47

标签: php .htaccess mod-rewrite mirror

我希望domain.tld/en/domain.tld/及其所有(子)目录和文件的100%镜像,但不会更改其客户端的URL。目前PHP文件无法访问所有需要的文件(如CSS),因为他们无法在domain.tld/en/css/file.css中找到它们(仅在/css/file.css中应该是相同的)

这就是我的.htaccess现在的样子(改编自另一个问题(见下文)):

RewriteEngine On 
RewriteRule /en/(.*) /$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php

背景

我无法在stackoverflow上找到我的问题的解决方案。 它非常接近这个问题Redirect from one directory to another with mod_rewrite,但因为我真的不明白如何修改htaccess文件,所以它对我没有帮助,遗憾的是。

我在主目录的index.php中运行了一个网站,例如domain.tld/index.php,现在我已经修改了php文件,其中包含多语言内容的可替换字符串以及检测其使用的目录。

1 个答案:

答案 0 :(得分:1)

根目录中的文件与其他目录中的文件之间应该没有任何区别。试试这个(请注意,我添加了L标记,这会使mod_rewrite在第一个匹配时停止寻找其他规则(在您的情况下,en/下的任何文件都应该有匹配第一个和第二个规则 - 因此它将应用两个重写

RewriteEngine On
RewriteRule ^\/?en\/(.*) $1?lang=en [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
相关问题