我正在使用.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]
我认为这个问题属于最后一条规则。有什么建议吗?
答案 0 :(得分:0)
.htaccess
会一直重写。在您使用END
标志内部重写网址后强制它停止重写:
# Internally rewrite extensionless URL to corresponding .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)$ $1.php?%1 [NC,END,QSA]