我确信这已经得到了解答,我现在已经阅读了几个小时而且无处可去。今晚我需要这个工作,我的大脑很伤人,所以我要求美妙的网络寻求帮助。
我正试图通过index_new.php
运行我的所有页面(当我决定这样做时,这一切都是有道理的,我发誓)。我有两种类型的页面,静态和动态。动态页面都是相同类型的页面,但基于数据库(MySQL)的数据不同。我正在尝试进行这些重写
(如果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
或任何其他页面时,我会收到HTTP 404.请注意,我的根目录是http://localhost/~user/public_html/new
,而.htaccess
文件就在那里。
答案 0 :(得分:2)
本发明提供:
每条规则都必须符合问题的条件。 (它们被重复,因为它们仅对下一个重写规则有效。)
.htaccess文件位于root。
您可以在问题中尝试此操作而不是规则集:
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]