2016-06-10 119 views
3

.htaccess文件看起来像这样:htaccess的&301个重定向造成服务器速度变慢

RewriteEngine on 

RewriteBase/

RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com [NC] 
RewriteRule ^(.*)$ http://mywebsite.com/$1 [L,R=301] 

RewriteCond %{HTTPS} !on 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

RewriteRule ^resources/([^/\.]+)/?$ page.php?theme=resources&pg=$1 [L] 
RewriteRule ^resources/([^/\.]+)/?/([^/\.]+)/?$ page.php?theme=resources&pg=resources&catname=$1&cat=$2 [L] 
RewriteRule ^resources/([^/\.]+)/?/([^/\.]+)/?/([^/\.]+)/?$ page.php?theme=resources&catname=$1&cat=$2&pg=$3 [L] 

RewriteRule ^albums/([^/\.]+)/?/([^/\.]+)/?$ page.php?theme=albums&pg=albums&albumname=$1&album=$2 [L] 
RewriteRule ^albums/([^/\.]+)/?$ page.php?theme=albums&pg=albums [L] 

RewriteRule ^leaving-the-site/([^/\.]+)/?$ page.php?theme=leaving-the-site&pg=leaving-the-site&q=$1 [L] 

RewriteRule ^([^/\.]+)/?/([^/\.]+)/?$ page.php?theme=$1&pg=$2 [L] 

RewriteRule ^([^/\.]+)/?$ page.php?theme=$1&pg=$1 [L] 

似乎一切都很好,但我们正在重新推出该网站,我们有大约110 301重定向,我们需要落实到位。这些格式相似以下,并添加上述重写规则后:

RewriteRule ^about/about-the-site$ https://www.mywebsite.com/about-us? [L,NC,R=301] 

我的问题是,一旦我有所有的301S上传htaccess文件,它开始现场放缓,到在大约10分钟内有60秒的加载时间,然后开始超时。

我删除了301重定向,然后恢复。从我的研究中,301重定向可能会降低服务器速度,但“不显着”,至少不会少于1000条。

有什么我应该做的不同吗?

+0

必须使用的.htaccess(你可以访问apache的conf文件)? –

+0

如果您有权访问apache配置文件,您可以使用'RewriteMap'加快.htaccess加载时间 – anubhava

+0

我对“RewriteMap”一无所知,因此我将开始研究它。我应该能够访问conf文件;我只是没有 – TH1981

回答

0

这是结合HTTPS/SSL & WWW到非WWW重写|专门为WordPress重定向htaccess代码,但您可以修改/定制它为您的特定网站。我仍在看你的其他代码...

编辑:好吧,我看着你的其他代码,它是过于复杂,并且在你的代码中使用问号可能是不正确的。我建议你做的是使用RewriteCond查询字符串匹配代码,而不是你正在尝试使用的方向/代码。请参见本主题例如的RewriteCond查询字符串匹配htaccess的代码示例:Replace "index.php?option=com_k2&view=item&id=" using .htaccess and Regex

# WP REWRITE LOOP START 
# Rewrite|Redirect http to https|SSL & www to non-www 
RewriteEngine On 
RewriteBase/
RewriteCond %{HTTPS} !=on 
RewriteCond %{SERVER_PORT} ^80 
RewriteCond %{HTTP_HOST} ^www\.domainname\.com$ [NC] 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] 
RewriteRule ^index\.php$ - [L] 

# All lines of Rewrite|Redirect code would go here 

# if file or directory does not exist then Rewrite to index.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
# WP REWRITE LOOP END