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

时间:2019-04-15 19:59:48

标签: .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

1 个答案:

答案 0 :(得分:1)

您的规则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]

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