我正在处理我的 .htaccess 以获得一个无扩展名的站点。我在网上搜索并实施了一些有效的规则,但是当我输入一个不存在的 url(例如 mysite.com/dsfadfasdf )时,它开始进入无限循环。
如果有人愿意帮助我摆脱循环并可能重定向到我选择的页面(我会说该页面不存在),我将非常感激!
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
# Redirect www to non www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Home page language
RewriteRule ^(en|ro)/?$ index.php?lang=$1 [L]
# For the profile page
RewriteRule ^(.+)\/accommodation-(.+)\/([0-9]+)\/(.+)$ location.php?id=$3&town=$2&hname=$4&lang=$1 [NC,L]
# Internally rewrite extensionless URL to corresponding .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)$ $1.php?%1 [NC,L,QSA]
# Externally redirect (only) direct client requests for .php URLs to extensionless URLs:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php http://mysite.com/$1 [R=301,L]
我相信问题出在最后一条规则中。有什么建议么?