繁体   English   中英

htaccess重定向所有页面,但有些页面不起作用

[英]htaccess Redirect all pages except some not working

我正在尝试将网站上的所有页面重定向到首页,除了少数页面。 我发现了一些关于stackoverflow的解决方案,但是这些解决方案都无法正常工作,因此我认为可能与我自己编写的htaccess的其余部分存在冲突。

RewriteEngine on
# begin my code
RewriteCond %{REQUEST_URI} !^/agb$
RewriteCond %{REQUEST_URI} !^/impressum$
RewriteCond %{REQUEST_URI} !^/datenschutzerklaerung$
RewriteRule .* https://www.mywebsite.com [R=301,L]
# end my code
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^ https://www.%1%{REQUEST_URI} [NE,L,R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]

我试图写RewriteRule。* / [R = 301,L]

并且我还尝试将我的代码放在其余部分的下面,但这会导致重定向循环。

像这样尝试:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(agb|impressum|datenschutzerklaerung|)$
RewriteRule .* https://www.mywebsite.com [R=301,L]

在隐身模式下尝试使用新的浏览器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM