Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache htaccess删除www重定向到ssl但url错误_Apache_.htaccess_Redirect_Mod Rewrite_Url Rewriting - Fatal编程技术网

Apache htaccess删除www重定向到ssl但url错误

Apache htaccess删除www重定向到ssl但url错误,apache,.htaccess,redirect,mod-rewrite,url-rewriting,Apache,.htaccess,Redirect,Mod Rewrite,Url Rewriting,我用php创建了一个mvc框架。我唯一的工作主文件是index.php 通常我从http重定向到https。我也会删除www域,但是当我使用www进入时,如果我的URL是 domain.com/admin/products/edit/1, htaccess就是这样做的 domain.com/index.php/products/edit/1 我怎样才能解决这个问题 多谢各位 RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d Rewri

我用php创建了一个mvc框架。我唯一的工作主文件是index.php

通常我从http重定向到https。我也会删除www域,但是当我使用www进入时,如果我的URL是

domain.com/admin/products/edit/1, 
htaccess就是这样做的

domain.com/index.php/products/edit/1
我怎样才能解决这个问题 多谢各位

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^ index.php [L]

RewriteCond %{HTTPS} off

RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

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

您应该有这样的规则,始终保持https重定向规则只放在第一位。请在测试URL之前清除浏览器缓存(其余规则来自OP的试用规则+我在这里也更改了匹配主机名的正则表达式)


非常感谢你。为我工作
RewriteEngine ON

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{HTTP_HOST} ^(?:www\.)(example\.com) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^ index.php [L]