简体   繁体   English

Mod重写-.htaccess

[英]Mod Rewrite - .htaccess

I recently moved to https from http and i have a redirect chain that shows up in safari slowing down the load time of my site. 我最近从http转到了https,并且有一个重定向链,该链显示在野生动物园中,从而减慢了我网站的加载时间。

I've spent several days with bluehost and it seems no one knows/is willing to help re-write to the .htaccess file, it's also possibly not their job either, so fair enough. 我在bluehost中待了几天,似乎没人知道/不愿意帮助重写.htaccess文件,这也可能不是他们的工作,如此公平。 I've spend several hours myself and I now have a rough understanding but still could use a bit of help. 我本人已经度过了几个小时,现在我已经有了大致的了解,但仍然可以使用一些帮助。

My preferred domain is https://jambarteambuilding.com 我的首选域名是https://jambarteambuilding.com

the redirect chain in safari is http://www.jambarteambuilding.com then to https://www.jambarteambuilding.com then to https://jambarteambuilding.com 野生动物园中的重定向链是http://www.jambarteambuilding.com,然后是https://www.jambarteambuilding.com,然后是https://jambarteambuilding.com

What im aiming for is 我的目标是

 http://www.jambarteambuilding.com
 http://jambarteambuilding.com
https://www.jambarteambuilding.com

all to redirect to 全部重定向到

https://jambarteambuilding.com

also. 也。

My website and wordpress install is housed in a subdirectory called 'clean'. 我的网站和wordpress安装位于一个名为“ clean”的子目录中。 So public_html/clean where you will find wp-admin, wp-content, wp-includes. 所以public_html / clean在哪里您可以找到wp-admin,wp-content,wp-includes。

my .htaccess file is written so that if you type jambarteambuilding.com the website loads from the clean but you don't see jambarteambuilding.com/clean in the URL only jambarteambuilding.com (which is what i prefer). 编写我的.htaccess文件是为了使您键入jambarteambuilding.com,使网站从干净加载,但在URL中仅jambarteambuilding.com(我更喜欢)看不到jambarteambuilding.com/clean。

So 所以

This is my current .htaccess file. 这是我当前的.htaccess文件。

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^(www.)?jambarteambuilding.com$ 
RewriteCond %{REQUEST_URI} !^/clean/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /clean/$1 
RewriteCond %{HTTP_HOST} ^(www.)?jambarteambuilding.com$ 
RewriteRule ^(/)?$ clean/index.php [L]

My feeling is that I need to write an [OR] statement after line 2 to capture https://www.jambarteambuilding.com in the conditions. 我的感觉是,我需要在第二行之后写一个[OR]语句来捕获条件中的https://www.jambarteambuilding.com [NC]seems to be missing from line 2 and 7 R=301 seems to be missing form line 6 and 8 line 2 and 7 seem to be duplicated. [NC]似乎在第2行和第7行中丢失了R = 301在第6行和第8行中似乎已丢失,第2行和第7行似乎重复了。 the jambarteambuilding.com should be jambarteambuilding.com Im guessing that (www.)? jambarteambuilding.com应该是jambarteambuilding.com我猜(www。)吗? means 'with or without www' 表示“带有或不带有www”

Could anyone easily help rewrite this for me! 任何人都可以帮我轻松地重写它!

From this question . 这个问题 Something like this should work... 这样的事情应该起作用...

RewriteCond %{HTTPS} off 
RewriteCond %{HTTPS_HOST} !^jambarteambuilding.com$ [NC]
RewriteRule ^(.*)$ https://jambarteambuilding.com/$1 [L,R=301]

Or, if you are able to modify the Apache VirtualHost file then this would be better... 或者,如果您能够修改Apache VirtualHost文件,则更好。

<VirtualHost *:80>
    ServerName jambarteambuilding.com
    ServerAlias www.jambarteambuilding.com
    Redirect / https://jambarteambuilding.com/
</VirtualHost>
<VirtualHost *:443>
    ServerName jambarteambuilding.com
    ServerAlias www.jambarteambuilding.com
    # ... SSL configuration goes here
</VirtualHost>

This solved it! 这样解决了!

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTPS_HOST} !^jambarteambuilding.com$ [NC]
RewriteRule ^(.*)$ https://jambarteambuilding.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI} !^/clean/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /clean/$1
RewriteRule ^(/)?$ clean/index.php [L]

Thanks All! 谢谢大家!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM