Apache 为什么这个.htaccess不起作用?

Apache 为什么这个.htaccess不起作用?,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我写了这个.htacess文件,除了thread.php和profile.php规则之外,所有的东西似乎都在工作,除非我对其中一个规则进行注释,否则这两个规则不会同时工作。有什么问题吗 下面是代码 #1 --- prevent file listing in all of your folder ---- IndexIgnore * RewriteBase / Options +FollowSymLinks RewriteEngine on #2 Force www before SS

我写了这个.htacess文件,除了thread.phpprofile.php规则之外,所有的东西似乎都在工作,除非我对其中一个规则进行注释,否则这两个规则不会同时工作。有什么问题吗

下面是代码

#1 --- prevent file listing in all of your folder ----

IndexIgnore *

RewriteBase /

Options +FollowSymLinks

RewriteEngine on

#2 Force www before SSL
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

#3 Force SSL
<IfModule mod_ssl.c>
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

#4 index.php to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]

#5 App rewrites
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ /profile.php?user=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9]*)$ /thread.php?id=$1 [L]

AddDefaultCharset UTF-8

#6 Establish a custom 404 page not found ----

ErrorDocument 404 /404
#1---防止在所有文件夹中列出文件----
IndexIgnore*
重写基/
选项+FollowSymLinks
重新启动发动机
#2在SSL之前强制www
重写cond%{HTTP_HOST}^$
重写cond%{HTTP_HOST}^www\。[北卡罗来纳州]
在上重写cond%{HTTPS}s^|
重写规则^http%1://www.%{http_HOST}%{REQUEST_URI}[R=301,L]
#3强制SSL
重写cond%{HTTPS}=在…上
重写规则^https://%{HTTP_HOST}%{REQUEST_URI}[L,R=301]
#4 index.php到/
重写cond%{THE_REQUEST}^[A-Z]{3,9}\/.*index\.php\HTTP/
重写规则^(.*)索引\.php$/$1[R=301,L]
#5应用程序重写
重写cond%{REQUEST_FILENAME}-D
RewriteCond%{REQUEST_FILENAME}.php-f
重写规则^(.*)$$1.php
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^([^/]*)$/profile.php?用户=$1[L]
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^([0-9]*)$/thread.php?id=$1[L]
AddDefaultCharset UTF-8
#6未找到自定义404页----
错误文件404/404

问题在于您的配置文件规则也将匹配与线程规则匹配的任何内容。交换顺序,这样线程规则将首先执行,您应该可以。

您好,非常感谢。它现在正在工作,但你说“我有更大的问题”,请问可能是什么问题,以及我如何才能使代码更好。事实上,这是好的,我的错误,你正在检查的网址与现有的“.php”之前添加运行规则,所以它是确定的。我想说的是,进行如此多的文件系统检查对性能有害。这可能是一个更好的方法。但这是一个更大的问题,超出了范围;这需要重新思考整件事。请记住,对于每个请求,这将至少运行两次,因此请考虑文件系统需要检查多少次。请使用右上角的勾号接受我的答案,以表明它对您有效。欢迎使用堆栈溢出:)