0
# -FrontPage-

#<Limit GET POST>
#   order deny,allow
#   deny from all
#   allow from all
#</Limit>
<Limit PUT DELETE>
    order deny,allow
    deny from all
</Limit>

AuthUserFile /home1/tenleiye/public_html/_vti_pvt/service.pwd
AuthGroupFile /home1/tenleiye/public_html/_vti_pvt/service.grp

# Use PHP5 as default
AddHandler application/x-httpd-php5 .php
AuthName tenleiyen.com
#IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Force www
    RewriteCond %{HTTP_HOST} ^tenleiyen\.com
    RewriteRule ^(.*)$ http://www.tenleiyen.com/$1 [R=permanent,L]

    # Do not change or site will be f*ked. Restrict all except the list below, redirecting all traffic to the index.php
    RewriteCond $1 !^(index\.php|1\.ico|favicon\.png|apple-touch-icon(.*)|crossdomain\.xml|robots\.txt|css|js|images|uploads|videos|download|sitemap\.xml)
    RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

以前的程序员给我写了一个可爱的注释,表示我无法更改权限。如果我添加一些东西,甚至从中删除一个片段,RewriteCond它将 404。

我不能:

  1. 使用根目录,
  2. sitemap.xml读一读,
  3. 1.jpg在根目录中放置一个文件并查看它,
  4. 将我的网站管理员工具.html文件放入要读取的根目录中。

一切都将转到 index.php 文件,我所能做的就是使用指定的文件夹。

4

1 回答 1

1
RewriteCond %{HTTP_HOST} ^tenleiyen\.com
RewriteRule ^(.*)$ http://www.tenleiyen.com/$1 [R=permanent,L]

At this rule, the condition verify if your domain starts with tenleiyen.com, if so, it will rewrite the request to http://www.tenleiyen.com/$1.

The $1 stands for the value held at ^(.*)$ which basically means anything after the domain, for example http://www.tenleiyen.com/index.php.

The 2 flags at the end means permanent redirect aka 301 redirect and L stand for LAST as in last rule.


This one is slight complicated so I will go by parts:

RewriteCond $1 !^(index\.php|1\.ico|favicon\.png|apple-touch-icon(.*)|crossdomain\.xml|robots\.txt|css|js|images|uploads|videos|download|sitemap\.xml)
RewriteRule ^(.*)$ /index.php/$1 [L]

The $1 is whatever you capture first in the next RewriteRule in this case ^(.*)$ which is anything after the domain not counting the initial / see image below (more specifically follow the green line):

back-reference

So basically the right hand of the condition compares if the left hand start with any of those keywords:

  • index.php OR
  • 1.ico OR
  • favicon.png OR
  • apple-touch-icon(anything else after) OR
  • crossdomain.xml OR
  • robots.txt OR
  • css OR
  • js OR
  • images OR
  • uploads OR
  • videos OR
  • download OR
  • sitemap.xml

If it does not start with any of it then it will redirect it to the index.php.

If it matches with any of the above mentioned then it will give you direct access.

You will be able to access:

http://yourdomain.com/sitemap.xml

But won't be able to access

http://yourdomain.com/test/sitemap.xml

Now this is what I believe that you want:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /index.php/$1 [L]

The above rule will verify if a file, directory or symbolic link exists if it does then it will not redirect to the index.php if it doesn't then it will redirect to the index.php.

于 2013-08-11T19:43:17.443 回答