.htaccess remove index.php删除www.force https

.htaccess remove index.php删除www.force https,.htaccess,indexing,.htaccess,Indexing,我知道这不一定是一个特定于EE的问题,但它涉及到经典的EE从URL中删除index.php以及一些更具体的重写。这也是一个懒惰的问题,因为我已经尝试了一些重写规则组合,并且有错误…所以,我想要的是(请) 删除www 强制https:// 删除index.php 值得注意的是,在(mt)Media Temple服务器上,当在dev.domain.com等子域上进行测试时,传统的多重定向问题开始出现。理想情况下,有一种方法可以让一个.htaccess文件来管理它们。非常感谢。 # Enable

我知道这不一定是一个特定于EE的问题,但它涉及到经典的EE从URL中删除index.php以及一些更具体的重写。这也是一个懒惰的问题,因为我已经尝试了一些重写规则组合,并且有错误…所以,我想要的是(请)

  • 删除www
  • 强制https://
  • 删除index.php
值得注意的是,在(mt)Media Temple服务器上,当在dev.domain.com等子域上进行测试时,传统的多重定向问题开始出现。理想情况下,有一种方法可以让一个.htaccess文件来管理它们。非常感谢。


# Enable Rewrite Engine
RewriteEngine On
RewriteBase /

# Force https
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

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

#Remove index.php
#strip index.php from the URL if that is all that is given
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://%{HTTP_HOST}/ [R=301,NS,L,QSA]
#strip index.php/* from the URL
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php/ [NC]
RewriteRule ^index\.php/(.+) http://%{HTTP_HOST}/$1 [R=301,L,QSA]


# EE
#rewrite all non-image/js/css urls back to index.php if they are not files or directories
RewriteCond $1 !^(images|templates|themes)/ [NC]
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]
重新启动发动机 重写cond%{REQUEST_URI}^/js/*$ 重写规则^(.*)$/public/$1[QSA,L] 重写cond%{REQUEST_URI}^/css/*$ 重写规则^(.*)$/public/$1[QSA,L] 重写cond%{REQUEST_URI}^/images/*$ 重写规则^(.*)$/public/$1[QSA,L] 重写COND%{REQUEST_URI}^/fonts/*$ 重写规则^(.*)$/public/$1[QSA,L] 重写cond%{REQUEST_URI}^/themes/*$ 重写规则^(.*)$/public/$1[QSA,L] 重写cond%{REQUEST_URI}^/inc/*$ 重写规则^(.*)$/public/$1[QSA,L] 重写cond%{REQUEST_URI}^/admin.php$ 重写规则^(.*)$/public/$1[QSA,L] 重写cond%{REQUEST_URI}^/公共/*$ 重写规则^(.*)$/public/index.php?$1[QSA,L]
对我有效的是(不包括index.php部分,仅用于删除WWW和强制使用HTTPS),这是:

# Enable Rewrite Engine
RewriteEngine On

# Remove the www 
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# Force https, specify http_host
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^example\.com$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#-----the following part is untested, but should work to answer the full quesiton including the index.php part

#Remove index.php
#strip index.php from the URL if that is all that is given
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://%{HTTP_HOST}/ [R=301,NS,L,QSA]
#strip index.php/* from the URL
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php/ [NC]
RewriteRule ^index\.php/(.+) http://%{HTTP_HOST}/$1 [R=301,L,QSA]


# EE
#rewrite all non-image/js/css urls back to index.php if they are not files or directories
RewriteCond $1 !^(images|templates|themes)/ [NC]
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]

这个问题似乎离题了,因为它是关于apache设置的,而不是EE设置。你能展示你现有的.htsccess吗?看起来很棒@pvledoux,谢谢你。但是(也许我应该提到)在dev.server上,这会出现以前的过多重定向问题…你知道如何使用子域(用于开发和登台)实现这一点吗?可能是重定向循环,因为https(你在dev-box上使用https吗?)我不知道,因为我是MAMP luddite,但是我正在通过快速上传.htaccess到dev.并在那里看到结果来测试代码。在循环开始的地方,是否可以检测子域并进行处理?我想说,如果输入了www,这个命令将导致循环,因为第一个命令强制使用https,而第二行将返回http…我可以确认它在前面输入www时循环。所以:对不起,这对我不起作用。。
# Enable Rewrite Engine
RewriteEngine On

# Remove the www 
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# Force https, specify http_host
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^example\.com$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#-----the following part is untested, but should work to answer the full quesiton including the index.php part

#Remove index.php
#strip index.php from the URL if that is all that is given
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://%{HTTP_HOST}/ [R=301,NS,L,QSA]
#strip index.php/* from the URL
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php/ [NC]
RewriteRule ^index\.php/(.+) http://%{HTTP_HOST}/$1 [R=301,L,QSA]


# EE
#rewrite all non-image/js/css urls back to index.php if they are not files or directories
RewriteCond $1 !^(images|templates|themes)/ [NC]
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]