限制友好URL .htaccess的目录

时间:2013-06-12 05:40:12

标签: .htaccess url browser

我希望网站是url友好匹配,所以目录/ adm(在我的情况下是管理面板)没有url友谊赛

我的.htaccess

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
</IfModule>

# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [L]
</IfModule>

我只是想这样做我正在学习这个规则意味着在外行命令中。 htaccess的

1 个答案:

答案 0 :(得分:1)

所有脚本都将根据以下内容重定向到index.php

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

此外,您可以指定不符合上述规则的文件夹名称,文件名。这可以通过在htaccess文件中添加另一个重写条件语句来完成。

RewriteCond %{REQUEST_FILENAME} !(img|anyother folders that you want to ignore|anyother folders that you want to ignore|...)

'|'用于分隔您要忽略的每个文件夹名称

所以你的.htaccess文件会有以下内容

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
</IfModule>

# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} !(adm|anyother folders that you want to ignore|anyother folders that you want to ignore|...)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [L]
</IfModule>