.htaccess 重写 - 具有多级目录的 URL
我有一个页面 Deals.php ,该页面位于根目录中,可通过多个目录级别的内部 URL 访问该页面。例如,此页面将通过以下两个 URL 访问。
http://domain/flights/asia/bangkok
http://domain/flights/bangkok
我在 .htaccess 中使用此代码重定向到 Deals.php
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^flights/asia/([^/]+)/?$ deals.php?country=$1 [NC]
RewriteRule ^flights/([^/]+)/?$ deals.php?country=$1 [NC]
现在出现的问题是 Deals.php 上的所有图像、脚本和样式表文件都无法正确打开。如果我尝试通过在所有图像、脚本和 CSS 的地址中放置 ../../ 来针对一个 URL 修复此问题,则它不适用于其他 URL。
如何解决这个问题呢?有哪些选择?
I have a page deals.php which is placed at root directory that is being accessed by number of internal URLs with multi directory levels. for example this page would be accessed by both following urls.
http://domain/flights/asia/bangkok
http://domain/flights/bangkok
I am using this code in .htaccess to redirect to deals.php
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^flights/asia/([^/]+)/?$ deals.php?country=$1 [NC]
RewriteRule ^flights/([^/]+)/?$ deals.php?country=$1 [NC]
Now the problem here coming is that on deals.php all the images, script and style sheet files are not opening properly. If I try to fix it against one URL by placing ../../ in addresses of all images, script and css, it dont work for other URL.
How to solve this problem? what are the options?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简单:不要在指向任何资源(images/css/js/etc)的链接中使用
../
——始终使用以下 URL:相对于网站根目录——当您处理漂亮/不真实/重写的 URL 时,这是一个“要求”,因为此类 URL 很少指向物理文件位置。假设您有一个位于
http://www.example.com/images/logo.png
的徽标。现在,始终使用
/images/logo,而不是
.../images/logo.png
和/或../../images/logo.png
。 pngEasy: DO NOT use
../
in links to any resources (images/css/js/etc) -- always use URL that is relative to the WEBSITE ROOT -- that is a "requirement" when you dealing with nice/not-real/rewritten URLs as such URL rarely points to the physical file location.Lets assume you have a logo that is located at
http://www.example.com/images/logo.png
.Now, instead of
../images/logo.png
and/or../../images/logo.png
ALWAYS use/images/logo.png
.我认为你想要的是在html页面中放置一个baseurl,因此所有相对路径都将与baseurl相关,而不是导航栏中的当前URL
i think what you want is placing an baseurl in html page, so all the relative path will related to the baseurl, not the current URL in the navigator bar