2017-05-05 153 views
1

我寫了這個.htacess文件,除了thread.phpprofile.php規則,這兩條規則不會同時工作,除非我對其中的一條發表評論。可能是什麼問題呢?下面爲什麼這個.htaccess不起作用?

是代碼

#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

你好,非常感謝。它現在正在工作,但你說「我有更大的問題」,請問可能是什麼問題,以及如何使代碼更好。 – idlatest

+0

其實沒關係,我的錯誤是,您正在檢查運行規則之前添加了「.php」的URL,因此沒關係。我想說的是,對於具有如此多文件系統檢查的性能來說這是不利的。它可能可以做得更好。但這是一個更大的問題,超出了範圍。它需要重新考慮整個事情。請記住,每次請求都會至少運行兩次,因此請考慮文件系統需要檢查多少次。 – SuperDuperApps

+0

請使用右上方的勾號接受我的回答,以顯示它適用於您。歡迎來到Stack Overflow :) – SuperDuperApps