Restrict directory for Friendly URLs .htaccess

2019-09-04 18:51发布

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条回答
干净又极端
2楼-- · 2019-09-04 19:34

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>
查看更多
登录 后发表回答