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

时间:2017-05-05 00:16:00

标签: 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 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 个答案:

答案 0 :(得分:1)

问题是您的配置文件规则还会匹配与线程规则匹配的任何内容。交换订单,所以线程规则先行,你应该没问题。