Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 修改规则404_Apache_Mod Rewrite - Fatal编程技术网

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
文件都在那里。

提供:

  • 每个规则都必须满足问题中的条件。(它们会重复,因为它们仅对下一个重写规则有效)

  • .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?没关系,大脑放屁。我的源路径是相对的,不再有效。再次感谢你的帮助。