简体   繁体   English

.htaccess重定向后如何访问父文件夹?

[英]How to access parent folders after .htaccess redirect?

I have a website that I need to be multilanguage. 我有一个需要多种语言的网站。 In a root folder I have an .htaccess that looks like this: 在根文件夹中,我有一个.htaccess,如下所示:

RewriteEngine on

RewriteCond %{HTTP:Accept-Language} (cs) [NC]
RewriteRule .* cs/index.php [L]

RewriteCond %{HTTP:Accept-Language} (de) [NC]
RewriteRule .* de/index.php [L]

I also have an index.php in root folder in default language (english). 我还在默认语言(英语)的根文件夹中有一个index.php。 If a customer comes to the website, i need to redirect him to appropriate language file. 如果客户访问该网站,我需要将他重定向到适当的语言文件。 The files are in the subfolders as you can see in the htaccess file. 这些文件位于htaccess文件中的子文件夹中。 (/cs, /de). (/ cs,/ de)。 The reason why I have these files in subfolder is, that customers to have an opinion to change language themselves. 我将这些文件放在子文件夹中的原因是,客户希望自己更改语言。 There are flags on the website that redirect them to appropriate folder manually. 网站上有一些标记,可以将它们手动重定向到适当的文件夹。 So far, everything worked fine, but there is a huge problem. 到目前为止,一切正常,但是存在一个巨大的问题。 After the automatic redirection, the website can't access the root subfolders with css and js files. 自动重定向后,网站无法使用css和js文件访问根子文件夹。 It behaves like the cs/index.php file is located in the root. 它的行为就像cs / index.php文件位于根目录中。 I am accessing the files through relative links like ../css/ because folders with these files are located in root directory. 我正在通过../css/等相对链接访问文件,因为包含这些文件的文件夹位于根目录中。

So, finally, my answer. 所以,最后,我的答案。 What should I change to make it work appropriately? 我应该进行哪些更改以使其正常工作? Thanks for every idea. 感谢您的每一个想法。

Change above rules to this: 将以上规则更改为此:

RewriteEngine on

RewriteCond %{HTTP:Accept-Language} (cs|de) [NC]
RewriteRule !\.(?:jpe?g|gif|bmp|png|tiff|css|js)$ %1/index.php [L,NC]

This will rewrite all requests except .css, .js & various images types to subfolders. 这会将除.css, .js & various images types以外的所有请求重写为子文件夹。

Also try adding this in the <head> section of your page's HTML: <base href="/" /> so that every relative URL is resolved from that URL and not the current page's URL. 也可以尝试将其添加到页面HTML的<head>部分中: <base href="/" />以便从该URL而不是当前页面的URL解析每个相对URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM