简体   繁体   English

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

[英]htaccess Redirect all pages except some not working

I'm trying to redirect all pages on my website to the homepage, except a few. 我正在尝试将网站上的所有页面重定向到首页,除了少数页面。 I found some solutions on stackoverflow but none of these are working so I assume there might be conflicts with the rest of my htaccess which I didn't write by myself. 我发现了一些关于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]

I have tried to write RewriteRule .* / [R=301,L] 我试图写RewriteRule。* / [R = 301,L]

and I've also tried to put my code beneath the rest, but this results in a redirect loop. 并且我还尝试将我的代码放在其余部分的下面,但这会导致重定向循环。

Try it like this: 像这样尝试:

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

Try in a new browser in incognito mode. 在隐身模式下尝试使用新的浏览器。

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

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