【发布时间】:2017-12-27 10:03:33
【问题描述】:
我正在尝试将我的重写规则添加到 httpd.conf 并禁用 .htaccess 以提高服务器性能。出于某种原因,我尝试过的所有方法都不起作用。
在我的主要httpd.conf 中,我已禁用AllowOverride 的所有实例,将它们设置为无。
我的虚拟主机块中的每个站点都有一个包含文件
Include "etc/apache2/conf.d/site.com/rewrite.conf"
然后在rewrite.conf 我有这样的东西:
<Directory "/home/shopmobilephones/public_html">
RewriteEngine On
ServerSignature off
# HTTP > HTTPS #########################################################################
RewriteCond %{HTTPS} off
RewriteRule (.*) https://shopmobilephones.co.uk%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^/www.shopmobilephones.co.uk [NC]
RewriteRule (.*) https://shopmobilephones.co.uk%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F,L]
RewriteRule ^/mobiles/deals/cash-back /cashback.php [L]
RewriteRule ^/mobiles/deals/cheap-mobile-phones /cheapmobilephones.php [L]
RewriteRule ^/mobiles/deals/clearance-deals /clearance.php [L]
RewriteRule ^/mobiles/deals/contracts /contractphones.php [L]
RewriteRule ^/mobiles/deals/12-months-free-line-rental /12month.php [L]
RewriteRule ^/mobiles/deals/top-deals /dailydeals.php [L]
RewriteRule ^/mobiles/deals/free-phones /freephones.php [L]
RewriteRule ^/mobiles/deals/new-mobile-phones /ladeals.php [L]
RewriteRule ^/mobiles/deals/sim-free-phones /simfree.php [L]
RewriteRule ^/mobiles/colours/(.*) /colours.php?colour=$1 [L]
RewriteRule ^/mobiles/(.*)/contract-deals /dealsnew.php?slug=$1&deal-type=1&device-type=Phone&network=all [L]
RewriteRule ^/mobiles/(.*)/upgrades /dealsnew.php?slug=$1&deal-type=2&device-type=Phone&network=all [L]
RewriteRule ^/mobiles/(.*)/contract-deals/(.*) /dealsnew.php?slug=$1&deal-type=1&device-type=Phone&NETWORK=$2 [L]
</Directory>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php56” package as the default “PHP” programming language.
<IfModule mime_module>
AddType application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
我尝试添加 RewriteBase / 并删除所有前缀 / 这不起作用我还从目录块中删除了规则这不起作用,我什至在主 httpd.conf 里面添加了规则和超出目录块但没有任何效果,我哪里出错了?
【问题讨论】:
-
什么是 Apache 版本?
-
“没有任何作用”的说法是一个非常笼统和广泛的说法,我怀疑这是真的。请更具体地说明究竟是什么不起作用。最好是提供特定(匿名)请求 URL、您的期望和实际结果。请在问题中添加此类详细信息,而不是在 cmets 中。
标签: apache mod-rewrite httpd.conf