Php 将长URL重定向到https

Php 将长URL重定向到https,php,apache,.htaccess,ssl,https,Php,Apache,.htaccess,Ssl,Https,在解决了避免重定向URL特定部分的问题后,我现在正试图解决将一个长的、更复杂的URL重定向到https的问题 这是我的.htaccess文件中给出问题的行: RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L] index.php永远不会在URL本身中公开。例如,此URL应重定向到https: 输入URL后,它将重定向到: [https://bootstrapcovers.com/index.php?uri=themes/bootstrap-themes/t

在解决了避免重定向URL特定部分的问题后,我现在正试图解决将一个长的、更复杂的URL重定向到https的问题

这是我的.htaccess文件中给出问题的行:

RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]
index.php永远不会在URL本身中公开。例如,此URL应重定向到https:

输入URL后,它将重定向到:

[https://bootstrapcovers.com/index.php?uri=themes/bootstrap-themes/toolsmith-1110/volvox-responsive-html5-bootstrap-template][2]
请注意,添加了index.php?uri=,这是我所期望的,但是页面被重新接收回主页。如果我删除该部分(index.php?uri=),url就会工作

如何在不添加index.php的情况下重定向URL?uri=

这是我完整的.htaccess文件:

# 1 Month for most static assets
<filesMatch ".(css|jpg|jpeg|png|gif|js|ico|woff)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
<IfModule mod_headers.c>
  <FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css|css)$">
    Header set Access-Control-Allow-Origin "*"
  </FilesMatch>
</IfModule>

Options -MultiViews
RewriteEngine on
RewriteRule ^(.+?)/$ /$1 [R=302,NE,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]

RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !\s/+preview [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]

RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} \s/+preview [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
#大多数静态资产为1个月
标题集缓存控制“最大年龄=2592000,公共”
标题集访问控制允许原点“*”
选项-多视图
重新启动发动机
重写规则^(+?)/$/$1[R=302,NE,L]
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(+)$index.php?uri=$1[QSA,L]
重写条件%{HTTPS}关闭
重写cond%{THE_REQUEST}\s/+预览[NC]
重写规则^(.*)$https://%{HTTP_HOST}%{REQUEST_URI}[NE,L,R=301]
在上重写cond%{HTTPS}
RewriteCond%{THE_REQUEST}\s/+preview[NC]
重写规则^http://%{http_HOST}%{REQUEST_URI}[NE,L,R=301]
如果您能帮助解决此问题,我们将不胜感激

谢谢,
-Paul

您需要对规则进行重新排序和重构。这样做:

# 1 Month for most static assets
<filesMatch ".(css|jpg|jpeg|png|gif|js|ico|woff)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
<IfModule mod_headers.c>
  <FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css|css)$">
    Header set Access-Control-Allow-Origin "*"
  </FilesMatch>
</IfModule>

Options -MultiViews
RewriteEngine on
RewriteBase /

RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !\s/+preview [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]

RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} \s/+preview [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [R=301,NE,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]
#大多数静态资产为1个月
标题集缓存控制“最大年龄=2592000,公共”
标题集访问控制允许原点“*”
选项-多视图
重新启动发动机
重写基/
重写条件%{HTTPS}关闭
重写cond%{THE_REQUEST}\s/+预览[NC]
重写规则^(.*)$https://%{HTTP_HOST}%{REQUEST_URI}[NE,L,R=301]
在上重写cond%{HTTPS}
RewriteCond%{THE_REQUEST}\s/+preview[NC]
重写规则^http://%{http_HOST}%{REQUEST_URI}[NE,L,R=301]
重写cond%{REQUEST_FILENAME}-D
重写规则^(+?)/$/$1[R=301,NE,L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(+)$index.php?uri=$1[QSA,L]

在测试此更改之前,请确保清除浏览器缓存。

anubhava,我的URL中没有uri参数……这是必要的吗?谢谢你的反馈,但我在回答中没有提到
url参数
。对于这个要求,我的回答是:
在不添加index.php的情况下如何重定向URL?uri=?
在清除浏览器缓存后,您是否测试了我建议的更改。我测试了您的更改,一切都很好。当我删除.htaccess文件中的最后一个条目时,它会失败。我的URL都没有使用这种格式(index.php?uri=),所以我想我不明白为什么它会失败。。。