0

现在我有一些 htaccess 规则来重写我的 url 从 example.com?node=home 到 example.com/home 和 example.com?node=gallery&id=56 到 exmaple.com/gallery/56。它还修复了我的链接、css样式表、照片等网页本身的目录路径已正确链接,现在所有这些都可以正常工作,我遇到的问题是如果我尝试访问 example.com /filename.jpg,它认为 filename.jpg 是它应该尝试加载的页面,而不是把我带到目录。那么为什么会这样,我该如何解决这个问题,并且仍然让我的 htaccess 规则正常工作呢?

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
## don't do anything
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/([^/]+)/?$ index.php/?node=$1&id=$2 [L,QSA]

RewriteRule ^([^/]+)/?$ index.php/?node=$1 [L,QSA]

现在我在 index.php 页面上也有:

<base href="http://www.mysite.com">
4

1 回答 1

0

尝试将您的代码更改为:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^([^/]+)/([^/]+)/?$ index.php/?node=$1&id=$2 [L,QSA]

## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^([^/]+)/?$ index.php/?node=$1 [L,QSA]
于 2013-07-07T07:33:09.457 回答