Apache 修改规则404
我相信这个问题已经得到了回答,我已经读了几个小时了,但毫无进展。今晚我需要这个来工作,我的大脑受伤了,所以我向奇妙的互联网寻求帮助 我试图通过Apache 修改规则404,apache,mod-rewrite,Apache,Mod Rewrite,我相信这个问题已经得到了回答,我已经读了几个小时了,但毫无进展。今晚我需要这个来工作,我的大脑受伤了,所以我向奇妙的互联网寻求帮助 我试图通过index\u new.php运行我的所有页面(我发誓,当我决定这么做时,这一切都是有意义的)。我有两种类型的页面,静态和动态。动态页面都是相同类型的页面,但是基于数据库(MySQL)的数据不同。我正试图重写这些 /about=>index_new.php?page=about /installations=>index_new.php?page=abo
index\u new.php
运行我的所有页面(我发誓,当我决定这么做时,这一切都是有意义的)。我有两种类型的页面,静态和动态。动态页面都是相同类型的页面,但是基于数据库(MySQL)的数据不同。我正试图重写这些
- /about=>index_new.php?page=about
- /installations=>index_new.php?page=about
- /安装/{site\u id}=>index\u new.php?page=site&siteID={site\u id}
about
可以是通用的,但我不想碰运气)我的.htaccess文件是:
# enable rewrite
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# rewrite all physical existing file or folder
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
# allow things that are certainly necessary
RewriteCond %{REQUEST_URI} "/statics/" [OR]
RewriteCond ${REQUEST_URI} "/ajax/"
# rewrite rules
RewriteRule ^about index_new.php?page=about
RewriteRule ^/installations index_new.php?page=list
RewriteRule ^/installations/(.*) index_new.php?page=site&id=$1
当我尝试转到/about
或任何其他页面时,我得到了HTTP404。请注意,我的根是http://localhost/~user/public\u html/new
和.htaccess
文件都在那里。提供:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /about/?$ [NC]
RewriteRule .* /index_new.php?page=about [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /installations/?$ [NC]
RewriteRule .* /index_new.php?page=list [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /installations/([^/]+)/? [NC]
RewriteRule .* /index_new.php?page=site&id=%1 [NC,L]
静默映射:
http://example.com/about
到
http://example.com/index_new.php?page=about
http://example.com/installations
到
http://example.com/index_new.php?page=about
http://example.com/installations/Anything
到
http://example.com/index_new.php?page=site&Anything
对于永久和可见重定向,请将[NC,L]替换为[R=301,NC,L] 注: 问题中的这些条件未被使用,因为其目的不明确:
RewriteCond %{REQUEST_URI} "/statics/" [OR]
RewriteCond ${REQUEST_URI} "/ajax/"
要将它们包含在一个或多个规则中,请尝试以下操作:
# For NOT condition, include the next line before the corresponding rewrite rule:
RewriteCond %{REQUEST_URI} !(statics|ajax) [NC]
# For positive condition, include the next line before the corresponding rewrite rule:
RewriteCond %{REQUEST_URI} (statics|ajax) [NC]
我建议你创建一个
RewriteLog
指令,将RewriteLogLevel
设置得很高,这应该会给你一些答案。你知道为什么如果我导航到/installations/a
Firebug会告诉我,我的JS文件中有一个语法错误,在'`处,而我的页面加载了所有资源,它不应用CSS或调用JS?没关系,大脑放屁。我的源路径是相对的,不再有效。再次感谢你的帮助。