HTTPS和尾随斜线后通过htaccess添加URL

时间:2015-11-18 00:26:55

标签: regex apache .htaccess mod-rewrite https

以下是最近添加的htaccess代码,用于向我的网址添加尾部斜杠和HTTPS,例如从http://www.example.com.au/resthttps://www.example.com.au/rest/

RewriteEngine On

#Trailing backslash
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.example.com.au/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* [QSA,L]

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

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php?/$1 [L]

如果点击该网站的链接,有时会这样做:https://www.example.com.au/more_of_the_url/last_of_url/?/[QSA,L]/last_of_url/

正确的网址是:https://www.example.com.au/more_of_the_url/last_of_url/

这里出了什么问题?请帮忙

更多信息: 所以我已经制定了一个解决方案,让用户访问该页面,但URL仍然不正确。通过将以下代码移动到htaccess文件的底部,重定向工作并将它们放在真实页面上。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* [QSA,L]

现在让用户登陆:https://www.example.com.au/more_of_the_url/last_of_url/?/more_of_the_url/last_of_url/

这应该是这样的: https://www.example.com.au/more_of_the_url/last_of_url/

0 个答案:

没有答案