htaccess 中的 https 和规则顺序(使用表达式引擎)
我正在表达式引擎中构建一个网站,其中一部分需要是 https。该网站还使用了新域名(新域名 www.example-new.com,旧域名 www.example.old.com)。
我想做以下事情:
- 删除index.php
- 强制www
- 强制https对于任何以www.example.old.com/extranet开头的URL
- 重定向https URL不是www.example.old.com/extranet(例如www.example .old.com/news 到 http
到目前为止,我有以下代码可以满足前两个要求:
<IfModule mod_rewrite.c>
RewriteEngine On
# Force www
RewriteCond %{HTTP_HOST} ^example-new.com$ [NC]
RewriteRule ^(.*)$ http://www.example-new.com/$1 [R=301,L]
# Removes index.php
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
AddType x-httpd-php53 .php
我似乎在兜圈子,所以我有两个问题将帮助我编写其他重写(尽管随意分享建议...):
1)要求3和4的代码是否应该位于“删除index.php”代码之前?
2) 该位置是否对来自旧网站的重定向有任何影响,例如 www.example-old.com/some-link-here.asp 将被重定向到 www.example-new.com/some-new -链接在这里
谢谢,
格雷戈尔
I'm building a site in expression engine that part of needs to be https. The site is also using a new domain name (new one www.example-new.com the old one www.example.old.com).
I want to do the following things:
- remove the index.php
- force www
- force https for any url starting www.example.old.com/extranet
- redirect https URLs that are not www.example.old.com/extranet (e.g. www.example.old.com/news to http
I have the following code so far that works for the first two requirements:
<IfModule mod_rewrite.c>
RewriteEngine On
# Force www
RewriteCond %{HTTP_HOST} ^example-new.com$ [NC]
RewriteRule ^(.*)$ http://www.example-new.com/$1 [R=301,L]
# Removes index.php
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
AddType x-httpd-php53 .php
I seem to be going round in circles, so I've two questions that will help me write the other rewrites (although feel free to share suggestions...):
1) Should the code for requirements 3 and 4 be positioned before "removes index.php" code?
2) Does the position have any bearing on the redirects that will be coming from the old site e.g. www.example-old.com/some-link-here.asp will be redirected to www.example-new.com/some-new-link-here
Thanks,
Gregor
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
1) 从 ExpressionEngine URL 中删除“index.php”
2) 添加“www”到所有 URI
3) 对任何以 /extranet 开头的 URI 强制使用 https://
4) 重定向 https:// 不是 /extranet 的 URI
将所有内容放在一起,这是您的完整集合重写规则:
1) Remove 'index.php' from ExpressionEngine URLs
2) Add 'www' to all URIs
3) Force https:// for any URI starting with /extranet
4) Redirect https:// URIs that are not /extranet
Putting it all together, here's your complete set of RewriteRules:
规则按照您编写的顺序进行处理。我希望您希望网站首先重定向,然后执行删除索引,所以是的,它应该先进行
如果您对两个站点使用相同的目录,则您需要为一个站点的所有规则添加限制域的 RewriteCond 前缀。否则,规则的顺序(旧站点与新站点)很重要。
您从旧站点的重定向也应该包含新站点中的规则,例如确保您根据需要访问 http/s 以避免额外的重定向。
下面是强制http/s的代码
The rules are processed in the order that you write them. I expect that you want the site to redirect first then do the remove index, so yes, it should go before
If you are using the same directory for both sites, then you would need to prefix all rules for one site with a RewriteCond that limits the domain. Otherwise, order of the rules (old vs new site) is important.
Your redirects from the old site should also incorporate rules in the new e.g. ensure that you are going to http/s as necessary to avoid extra redirects.
Below is the code to force http/s
如果有帮助的话...我昨天刚刚为一个电子商务网站做了这个...这是我的 .htaccess 文件
If it helps... I just did this yesterday for an ecommerce site... Here's my .htaccess file