Restrict directory for Friendly URLs .htaccess

僤鯓⒐⒋嵵緔 提交于 2020-01-07 04:58:09

问题


I want the site to be url friendly match, so that the directory / adm (which in my case is the administrative panel) has not url friendlies

my .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>

I just want to do this I'm learning this rule means in layman commands. htaccess


回答1:


All your scripts will be redirected to index.php based on below

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

In addition you can specify the folder name, filename which should not follow the above rule. This can be done by adding another rewrite condition statement in your htaccess file.

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

'|' is used to separate each folder name that you want to ignore

So your .htaccess file will have following

<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>


来源:https://stackoverflow.com/questions/17058362/restrict-directory-for-friendly-urls-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!