【问题标题】:.htaccess flat link.htaccess 平面链接
【发布时间】:2012-05-16 23:18:09
【问题描述】:

我想使用这样的平面链接:

http://somedomain.com/about-us
http://somedomain.com/products-list
http://somedomain.com/product/item    

因此我使用了这样的 mod_rewrite 规则:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([0-9A-Za-z-]+)?$  /index.php?page=$1 [L]
    RewriteRule ^([0-9A-Za-z-]+)/([0-9A-Za-z-]+)?$ /index.php?page=$1&value=$2 [L]
</IfModule>

前两个链接工作正常。但是每当我访问第三种类型的链接时,图像或 css 或任何链接为相对路径的 js 脚本,例如。 &lt;img src="images/image.jpg"&gt;&lt;a href="about-us"&gt;About Us&lt;/a&gt;

浏览器认为它在http://somedomain.com/product/images/image.jpghttp://somedomain.com/product/about-us中。

正确的路径应该是http://somedomain.com/images/image.jpghttp://somedomain.com/about-us

因此具有相对链接的文件不起作用。

如何解决这个问题?我不想对所有链接文件使用完整路径而不是相对路径。请通过在 .htaccess

中进行一些调整来提出一种方法

【问题讨论】:

    标签: .htaccess mod-rewrite url-rewriting relative-path


    【解决方案1】:

    尝试转义你的斜线:

    RewriteRule ^([0-9A-Za-z-]+)\/([0-9A-Za-z-]+)?$ /index.php?page=$1&value=$2 [L]
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-27
    • 1970-01-01
    • 1970-01-01
    • 2018-07-24
    • 1970-01-01
    • 2017-03-01
    • 2023-03-14
    相关资源
    最近更新 更多