.htaccess删除index.php删除www。强制https

时间:2014-07-16 09:51:37

标签: .htaccess indexing

我理解这不一定是EE特定的问题,但它涉及从URL中删除index.php的经典EE以及一些更具体的重写。这也是一个懒惰的问题,因为我尝试了一些重写规则组合并且存在错误......所以,我所追求的是(请)。

  • 删除www。
  • 强制https://
  • 删除index.php

重要的一点是,在(mt)Media Temple服务器上测试dev.domain.com这样的子域时,好的旧的多个重定向问题正在发挥作用。理想情况下,这是一种方法。一个.htaccess文件来统治它们。非常感谢提前。

3 个答案:

答案 0 :(得分:0)

# 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]

答案 1 :(得分:0)

对我有用的(不包括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]

答案 2 :(得分:-1)

<IfModule mod_rewrite.c>

   RewriteEngine on

   RewriteCond %{REQUEST_URI} ^/js/.*$

   RewriteRule ^(.*)$ /public/$1 [QSA,L]

   RewriteCond %{REQUEST_URI} ^/css/.*$

   RewriteRule ^(.*)$ /public/$1 [QSA,L]

   RewriteCond %{REQUEST_URI} ^/images/.*$

   RewriteRule ^(.*)$ /public/$1 [QSA,L]

   RewriteCond %{REQUEST_URI} ^/fonts/.*$

   RewriteRule ^(.*)$ /public/$1 [QSA,L]    

   RewriteCond %{REQUEST_URI} ^/themes/.*$

   RewriteRule ^(.*)$ /public/$1 [QSA,L]

   RewriteCond %{REQUEST_URI} ^/inc/.*$

   RewriteRule ^(.*)$ /public/$1 [QSA,L]

   RewriteCond %{REQUEST_URI} ^/admin.php$

   RewriteRule ^(.*)$ /public/$1 [QSA,L]    

   RewriteCond %{REQUEST_URI} !^/public/.*$ 

   RewriteRule ^(.*)$ /public/index.php?$1 [QSA,L]

</IfModule>
相关问题