Mod 重写 - 重定向问题 - 本地服务器没问题,实时服务器不行
以下内容有一点问题:
RewriteEngine On
RewriteOptions Inherit
RewriteBase /
#Add trailing slash if not a directory or file, but not if it contains a dot
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule .*[^/]$ $0/ [L,R=301]
# Don't redirect these directories
RewriteRule ^/?_images/.+$ - [L]
RewriteRule ^/?_lib/.+$ - [L]
RewriteRule ^/?_scripts/.+$ - [L]
RewriteRule ^/?_temp/uploads/.+$ - [L]
RewriteRule ^/?_template/.+$ - [L]
# Redirect via router, but not these files
RewriteCond %{REQUEST_URI} !^(\/!favicon.ico|robots.txt|sitemap.xml).*$
RewriteCond %{REQUEST_URI} !^\/$
RewriteRule ^(.*)$ index.php?route=$1 [QSA,L]
我遇到的问题是“不重定向目录” - 基本上这些文件夹中的文件仍应显示, - 这是正常工作的,但我在显示某些内容时遇到了一些麻烦来自 /_lib/images/
目录 - 由于某种原因,我总是收到 404 错误(可能是因为它通过路由器)。
通过显示错误号进行仔细检查,它实际上似乎是 406 错误(我以前没有遇到过),而 404 可能是由于没有 406 错误页面而导致的。
奇怪的是,它在 XAMPP 本地运行得很好,但在实时服务器上却不行 - 另外,如果我将 _lib/images/
重命名为 _lib/a/
它会完美地工作......所以问题是,我在这里完全错过了一些东西吗?即使是简单的“hello world”结果也是一样的......
Having a bit of a problem with the below:
RewriteEngine On
RewriteOptions Inherit
RewriteBase /
#Add trailing slash if not a directory or file, but not if it contains a dot
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule .*[^/]$ $0/ [L,R=301]
# Don't redirect these directories
RewriteRule ^/?_images/.+$ - [L]
RewriteRule ^/?_lib/.+$ - [L]
RewriteRule ^/?_scripts/.+$ - [L]
RewriteRule ^/?_temp/uploads/.+$ - [L]
RewriteRule ^/?_template/.+$ - [L]
# Redirect via router, but not these files
RewriteCond %{REQUEST_URI} !^(\/!favicon.ico|robots.txt|sitemap.xml).*$
RewriteCond %{REQUEST_URI} !^\/$
RewriteRule ^(.*)$ index.php?route=$1 [QSA,L]
The problem I'm having is the 'not redirecting directories' - basically files in these folders should still show, - this was working correctly, but I'm having a bit of trouble displaying something from the /_lib/images/
directory - for some reason I always get a 404 error thrown up (possibly because it goes via the router).
On closer examination by displaying the error number, it actually seems to be a 406 error (which I've not come across before) and the 404 probably results from not having a 406 error page.
The weird thing is, it works perfectly locally on XAMPP but not on the live server - also, if I rename _lib/images/
to, say, _lib/a/
it will work perfectly ... so the question is, am I completely missing something here? Even a simple 'hello world' results the same....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您没有在服务器上设置图像文件类型的关联。将图像移动到 DOCROOT,然后尝试显示它。如果返回 406,则您需要设置正确的文件关联。
Sounds like you don't have the associations for your image file types set up on the server. Move an image to DOCROOT, and then try to display it. If it returns a 406, then you need to set up the correct file associations.