0

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

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 脚本,例如。<img src="images/image.jpg"><a href="about-us">About Us</a>

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

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

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

如何解决这个问题?我不想对所有链接文件使用完整路径而不是相对路径。请通过在.htaccess中进行一些调整来提出一种方法

4

1 回答 1

0

尝试转义你的斜线:

RewriteRule ^([0-9A-Za-z-]+)\/([0-9A-Za-z-]+)?$ /index.php?page=$1&value=$2 [L]
于 2012-05-16T23:22:12.310 回答