htaccess URL 重写 如何避免重写点 (.) 页面


htaccess url rewrite how to avoid rewriting dot (.) pages

在我的.htaccess中,我有以下内容:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^mydomainname.com$ [NC]
RewriteRule ^(.*)$ http://mydomainname.com/$1 [R=301,L]
RewriteRule ^([A-Za-z0-9' -]+)$ index.php?x=$1 [L]

它的作用是重写 mydomainname.com/page-name 以 mydomainname.com/index.php?x=page-name

我的问题是我希望能够在不激活规则的情况下访问像 mydomainname.com/testpage.php 这样的页面。我不明白为什么当我在重写规则中没有点时它仍然加载索引页。

基本上你告诉所有内容都转到索引.php文件,简而言之是:

RewriteRule . index.php [L]

试试这个,让我们看看会发生什么:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^mydomainname.com$ [NC]
RewriteRule ^(.*)$ http://mydomainname.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9' -]+)$ index.php?x=$1 [L,QSA]