简体   繁体   English

htaccess url重写如何避免重写点(。)页面

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

in my .htaccess I have following: 在我的.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]

what it does is rewriting mydomainname.com/page-name to mydomainname.com/index.php?x=page-name 它的作用是将mydomainname.com/page-name重写为mydomainname.com/index.php?x=page-name

my problem is that I want to be able to access pages like mydomainname.com/testpage.php without the rule activating. 我的问题是我希望能够在不激活规则的情况下访问mydomainname.com/testpage.php之类的页面。 I don't understand why it still loads the index page when I dont have a dot in the RewriteRule. 我不明白为什么当我在RewriteRule中没有点时仍然加载索引页。

Basically your telling everything to go to the index.php file which in short is: 基本上,您告诉所有内容转到index.php文件,简而言之是:

RewriteRule . index.php [L]

Try this out and lets see what happens: 试试看,看看会发生什么:

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM