2012-02-15 90 views
-1

我需要将两个重写条件合并成一个我发现搜索网络的条件。问题是,如果一个作品其他的不会:需要帮助在.htaccess中使用mod_rewrite合并两个重写规则

### [RULE1: remove the .php at end of file/url] 
# If requested URL-path plus ".php" exists as a file 
RewriteCond %{DOCUMENT_ROOT}/$1.php -f 
# Rewrite to append ".php" to extensionless URL-path 
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L] 

而且

### [RULE2: http to https redirection] 
RewriteCond %{HTTPS} on 
RewriteCond %{HTTP_HOST} 
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] 

显然,无论规则被放置在顶级作品。

所以我需要一种方法来删除在url结尾处的php扩展,但是如果url包含http而不是https,它也应该自动重定向到https版本的脚本。

任何帮助将不胜感激!

回答

0

好像你正在设置每个页面通过https访问。我在下面纠正了一些错误。这样做:

#rule to make both WORK 
RewriteCond %{HTTPS} on 
### [RULE1: remove the .php at end of file/url] 
# If requested URL-path plus ".php" exists as a file 
RewriteCond %{DOCUMENT_ROOT}/$1.php -f 
# Rewrite to append ".php" to extensionless URL-path 
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L] 

### [RULE2: http to https redirection] 
RewriteCond %{HTTPS} off 
#The next line is not required. 
#RewriteCond %{HTTP_HOST} 
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] 
+0

工程就像一个魅力。谢谢! – user1212150 2012-02-16 11:46:16

+0

@ user1212150欢迎。请接受答案,以便Q/A将被关闭。 – ThinkingMonkey 2012-02-16 11:54:09