对http和https apache .htaccess重写规则相同

时间:2013-01-15 05:21:12

标签: .htaccess mod-rewrite https rewrite

我们从第三方提供商处购买了一些软件并继续安装ssl证书...当我们访问网站的http版本时,一切正常,但是当我们转到https时,浏览器会添加两个斜杠根网址的结尾,并重定向回到http网站...我不知道如何读取重写规则,但我们希望网站做同样的事情,无论是http还是https ...是否容易更新此方法:

DirectoryIndex index.html index.php
ErrorDocument 404 /handler.php
RewriteEngine on

Options +FollowSymlinks
RewriteBase /code
RewriteRule manage_articles\.php  /code/load_module.php?module_name=articles&file=manage_articles&%{QUERY_STRING} [L]
RewriteRule manage_articles_cat_frame\.php  /code/load_module.php?module_name=articles&file=manage_articles_cat_frame&%{QUERY_STRING} [L]
RewriteRule manage_articles_categories\.php  /code/load_module.php?module_name=articles&file=manage_articles_categories&%{QUERY_STRING} [L]
RewriteRule modify_article\.php  /code/load_module.php?module_name=articles&file=modify_article&%{QUERY_STRING} [L]
RewriteRule modify_article_cat\.php  /code/load_module.php?module_name=articles&file=modify_article_cat&%{QUERY_STRING} [L]
RewriteRule manage_letters\.php  /code/load_module.php?module_name=letters&file=manage_letters&%{QUERY_STRING} [L]
RewriteRule modify_letters\.php  /code/load_module.php?module_name=letters&file=modify_letters&%{QUERY_STRING} [L]


RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\/]+)\.html$ article.php?path=$1&%{QUERY_STRING} [L]
RewriteRule ^([^\/]+)\.htm$ article.php?cat_path=$1&%{QUERY_STRING} [L]
RewriteRule ^(article_[^\.]+\.gif)$ modules/articles/images/$1 [L]
RewriteRule ^auctions\/([^\/]+)\/*$ auction.php?title=$1&%{QUERY_STRING} [L]
RewriteRule ^auctions\/([^\/]+)\/buy_now$ buy_product.php?title=$1&%{QUERY_STRING} [L]

RewriteCond %{REQUEST_URI} !^(.*)(gif|jpg|css|png|js)$
RewriteRule ^.htaccess$ - [F]



# api rewrite logic
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^services\/(.*)$ services/api.php?rquest=$1 [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^services\/(.*)$ services/api.php [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^services\/(.*)$ services/api.php [QSA,NC,L]
#end api rewrite

同样,我希望网站功能完全相同,只需处理https。

感谢。

添加vhosts.conf:

# linkz.com ssl
<VirtualHost 164.175.65.135:443>
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLCertificateFile /usr/local/ssl/crt/publicbz.crt
SSLCertificateKeyFile /usr/local/ssl/private/private_nopp_bz.key
SSLCertificateChainFile /usr/local/ssl/crt/intermediate.crt
ServerAdmin webmaster@linkz.com
DocumentRoot /usr/local/www/micro
<Directory "/usr/local/www/micro">
AllowOverride All
DirectoryIndex index.html index.php
</Directory>
ServerName www.linkz.com
ServerAlias linkz.com
ErrorLog /var/log/httpd/linkz.error.log
#       CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
<VirtualHost 164.175.65.135:443>
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLCertificateFile /usr/local/ssl/crt/publicbz.crt
SSLCertificateKeyFile /usr/local/ssl/private/private_nopp_bz.key
SSLCertificateChainFile /usr/local/ssl/crt/intermediate.crt
ServerAdmin webmaster@linkz.com
DocumentRoot /usr/local/www/microdev
<Directory "/usr/local/www/microdev">
AllowOverride All
DirectoryIndex index.html index.php
</Directory>
ServerName dev.linkz.com
ServerAlias dev.linkz.com
ErrorLog /var/log/httpd/linkzdev.error.log
#       CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# linkz.com
<VirtualHost 164.175.65.135:80>
#       ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /usr/local/www/micro
<Directory "/usr/local/www/micro">
AllowOverride All
DirectoryIndex index.html index.php
</Directory>
ServerName www.linkz.com
ServerAlias linkz.com
ErrorLog /var/log/httpd/linkz.error.log
#       CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
<VirtualHost 164.175.65.135:80>
#       ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /usr/local/www/microdev
<Directory "/usr/local/www/microdev">
AllowOverride All
DirectoryIndex index.html index.php
</Directory>
ServerName dev.linkz.com
ServerAlias dev.linkz.com
ErrorLog /var/log/httpd/linkzdev.error.log
#       CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>

添加index.php:

if($_SERVER['SERVER_PORT']==443 && ($_SERVER['HTTP_HOST'] != 'www.auction.test' || $_SERVER['HTTP_HOST'] != 'www.default.loc'))
{
header('Location: '.$GLOBALS['SERVER_PATH'].$_SERVER['REQUEST_URI']);
exit;
}

1 个答案:

答案 0 :(得分:0)

这个问题是index.php文件......问题是我遇到了重写规则而且没想到要查看php文件。