.htaccess 重定向与文件中的其他代码冲突



我正在尝试更改我的.htaccess文件,以便在使用URL https://www.metaalboutique.nl/Contactformulier时显示页面https://www.metaalboutique.nl/contact_form.php

我的.htaccess文件中是否有一些与此冲突的代码,这可能是这不起作用的原因?

<Files .htaccess>
order allow,deny
deny from all
</Files>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
ErrorDocument 404 /index.php
RewriteCond %{HTTP_HOST} !^www.metaalboutique.nl$
RewriteRule ^(.*)$ https://www.metaalboutique.nl/$1 [R=301,L]
<IfModule mod_rewrite.c>
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} ^metaalboutique.nl$ [NC]
  RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.php [NC,L]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
Redirect 301 /closed/index.php    https://www.metaalboutique.nl
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?metaalboutique.nl [NC]
RewriteRule .(jpg|jpeg|png|gif)$ - [NC,F,L]
RewriteRule ^Contactformulier$ contact_form.php

您的规则RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([^.]+)$ $1.php [NC,L]重写所有不是要php目录的内容。这也匹配/Contactformulier并将其重写为 /Contactformulier.php 。您可以从 htaccess 中删除此规则,也可以使用以下修改后的 htaccess 版本。

<Files .htaccess>
order allow,deny
deny from all
</Files>
Redirect 301 /closed/index.php    https://www.metaalboutique.nl/
RewriteEngine on
#redirect http to https and non-www in a single redirect
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^metaalboutique.nl$ [NC]
RewriteRule (.*) https://www.metaalboutique.nl/$1 [R=301,L]
#deny access to remote referers
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?metaalboutique.nl [NC]
 RewriteRule .(jpg|jpeg|png|gif)$ - [NC,F,L]
#access .php files without using extension
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME}.php -f
 RewriteRule ^(.*)$ $1.php [L]
#rewrite /Contactformulier to /contact_form.php
 RewriteRule ^Contactformulier$ contact_form.php [L]

确保在测试之前清除浏览器缓存。

相关内容

最新更新