我的.htaccess中有以下内容:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /index.php?type=cat&id=$1 [QSA,L]
RewriteRule ^page/([^/]+)$ /index.php?type=page&name=$1
Run Code Online (Sandbox Code Playgroud)
这似乎工作得很好,但在第二种情况下(页面),index.php中的图片和css文件的相对路径会被破坏.不工作.在第二种情况下,所有图像都指向页面/图像/而不是图像/
除了硬编码图像的实际路径之外,还有其他方法可以解决这个问题吗?
images,css,js文件夹位于根目录中.这就是root的样子
.htaccess
index.php
images/
css/
js/
Run Code Online (Sandbox Code Playgroud)
RewriteCond指令仅适用于直接跟随它们的规则.请尝试以下操作
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /index.php?type=cat&id=$1 [QSA,L]
RewriteCond %{REQUEST_URI} !\.(css|js|jpe?g|gif|png)$ [NC]
RewriteRule ^page/([^/]+)$ /index.php?type=page&name=$1 [L]
#rewrite requests for page/images to images
RewriteCond %{REQUEST_URI} ^/page(/images/.+)$ [NC]
RewriteRule . %1 [L]
Run Code Online (Sandbox Code Playgroud)
编辑.修改为将图像/图像重写为图像
归档时间: |
|
查看次数: |
2215 次 |
最近记录: |