我有一个代码来重定向这样的链接
RewriteEngine On
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/([^/\.]+)?$ pages/index.php?p=$1&page=$2 [L]
RewriteRule ^([^/\.]+)?$ pages/index.php?p=$1 [L]
这样
localhost/mysite/a
localhost/mysite/a/b
转到
localhost/mysite/pages/index.php?p=a
localhost/mysite/pages/index.php?p=a&page=b
分别
我在index.php中有
的代码<img src='../pages/images/12345h1.png'>
img适用于localhost / mysite / a / b链接,但它不适用于localhost / mysite / a 有没有办法解决这个问题?
<{1}}和localhost/mysite/a/b
的
src变为localhost/mysite/a/
但对于localhost/mysite/pages/images/12345h1.png
src变为localhost/mysite/a
答案 0 :(得分:0)
问题是你的RewriteCond
只能应用于下一个立即的`RewriteRule。像这样更改.htaccess:
RewriteEngine On
Options +FollowSymLinks
# skip rules for files and directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([^/.]+)/([^/.]+)/?$ pages/index.php?p=$1&page=$2 [L,QSA]
RewriteRule ^([^/.]+)/?$ pages/index.php?p=$1 [L,QSA]