mod_rewrite 以及包含的 css、js、图像等文件和链接的相对路径存在问题
首先 - 我已经在 stackoverflow 和谷歌中搜索了很多答案,但到目前为止还没有成功找到可能的解决方案,任何建议将不胜感激。
问题是:
我有一个页面 www.mypage.com 并通过 GET 参数 lang 控制显示的语言 -> www.mypage.com/index.php?target=1&lang=en
现在,客户已在 united-domains 注册了一个域 (www.mypage. it)并希望我在请求域名 www.mypage.it 时显示该页面的意大利语版本。
提供商united-domains提供了一个名为URL-HIDING的解决方案,它基本上似乎将请求传递给我提供的URL+文件夹结构(例如www.mypage.com/lang/it< /em> - 根据 United-domains 的规范,它必须是文件夹结构,并且可能不是文件)
到目前为止的解决方案:
对域的调用:www.mypage.it 将被映射到www.mypage.com/lang/it/ 通过 URL-HIDING 选项。
.htaccess 文件将请求重写为实际目标:
RewriteEngine on
## check if query string contains NOT 'lang='
## (lang might be changed by user after initial request)
RewriteCond %{QUERY_STRING} !lang=
## redirect to page
RewriteRule ^(.*)$ http://www.mypage.com/index.php?target=1&lang=it
## check if query string contains 'lang='
RewriteCond %{QUERY_STRING} lang=
## Keep the existing query string using the Query String Append flag
RewriteRule ^(.*)$ http://www.mypage.com/index.php? [QSA]
问题当然是:CSS、javascript、图像...文件包含在
<link href="scripts/style.css" rel="stylesheet" type="text/css">
<script src="scripts/media.js" type="text/javascript">
<img src="images/logo.jpg">
<a href="download/test.pdf">PDF</a>
相对请求 scripts/style.css 映射到 http://www.mypage.com/lang/it/scripts/style.css
我很遗憾地陷入了 United-domains 的 URL 隐藏机制并更改了每个相对路径/scripts/media.js 不是一个选项,因为我必须更改相当多的代码。
有没有人有解决方案(恐怕我的 .htaccess 知识不是最好的) 我不能从每个请求中删除 lang/it/ 并另外检查 QUERY_STRING 是否包含字符串 lang= 以及是否简单添加 ?lang=感谢
迄今为止所有花时间阅读的人 - 如果有人有建议,我将不胜感激!
保持健康, 马蒂亚斯
First of all - I have searched quite a bit for an answer in stackoverflow and via google but haven´t been successfull so far to find a possible solution any advice would be greatly appreciated.
problem is:
I have a page
www.mypage.com
and controll the language displayed via a GET parameter lang
-> www.mypage.com/index.php?target=1&lang=en
Now a client has registered a domain at united-domains (www.mypage.it) and wants me display the italian version of the page whenever the domain www.mypage.it is requested.
The provider united-domains offers a solution called URL-HIDING which basically seems to pass the the request to a URL+folder structure I provide (like www.mypage.com/lang/it - according to the specifications of united-domains it has to be a folder structure and may not be a file)
solution so far:
Calls to the domain: www.mypage.it will be maped to www.mypage.com/lang/it/ via the URL-HIDING option.
there an .htaccess file rewrites the REQUESTS to the actual target:
RewriteEngine on
## check if query string contains NOT 'lang='
## (lang might be changed by user after initial request)
RewriteCond %{QUERY_STRING} !lang=
## redirect to page
RewriteRule ^(.*)$ http://www.mypage.com/index.php?target=1&lang=it
## check if query string contains 'lang='
RewriteCond %{QUERY_STRING} lang=
## Keep the existing query string using the Query String Append flag
RewriteRule ^(.*)$ http://www.mypage.com/index.php? [QSA]
Problem is of course: the CSS, javascript, image,... files are included with an relative path
<link href="scripts/style.css" rel="stylesheet" type="text/css">
<script src="scripts/media.js" type="text/javascript">
<img src="images/logo.jpg">
<a href="download/test.pdf">PDF</a>
therfore the relative request scripts/style.css is mapped to http://www.mypage.com/lang/it/scripts/style.css
I am sadly stuck the the URL-HIDING mechanism of united-domains and changing every relative path the /scripts/media.js is not an option as I´d have to change quite a bit of code.
Does anyone have a solution for this (my .htaccess knowledge is not the best I am afraid)
Couldn´t I just remove lang/it/ from EVERY request and additionally check if the QUERY_STRING contains the string lang= and if it does simple add ?lang=it
thanks to all that have taken the time to read so far - if anyone has a suggestion I´d be more than grateful !
stay well,
matthias
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎可以解决问题!
在文件夹中:
www.mypage.com/lang/it/
我输入:
This seems to do the trick !
in folder:
www.mypage.com/lang/it/
I put: