管理面板的htaccess重写规则

Mit*_*Sen 2 php .htaccess url-rewriting url-routing

我的网络应用程序中有url模式,如" www.mysitename.com/foldername/controller/method ".并且所有请求的页面首先在根文件夹上重定向到index.php,然后处理请求的页面.但每当我去管理面板(www.mysitename.com/admin)时,url会将"admin"作为文件夹名称,它会显示admin的index.php(这是正常的)然后使用controllernamemethodname它不会重定向到admin文件夹的index.php.

每当我访问"管理员"时,我都想要这个模式中的网址" www.mysitename.com/admin/foldername/controller/method ".以及通过admin的所有请求页面应首先重定向到admin文件夹上的index.php.这是我的htaccess文件 -

    Options -Indexes 
    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l

    RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Run Code Online (Sandbox Code Playgroud)

sjd*_*aws 6

.htaccess您的管理目录中是否有文件,或者根目录中只有一个文件?您需要在每个目录中都有一个.

我刚用你的.htaccessin /htdocs/pro和同样.htaccess/htdocs/pro/admin东西对它进行了测试,它完全像你解释的那样工作.

根htaccess in /htdocs/pro/.htaccess

Options -Indexes 
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Run Code Online (Sandbox Code Playgroud)

管理员htaccess in /htdocs/pro/admin/.htaccess

Options -Indexes 
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Run Code Online (Sandbox Code Playgroud)

单个htaccess文件,用于/htdocs/.htaccess/htdocs/pro/.htaccess

Options -Indexes
RewriteEngine on

# Change '/pro/' if directory is renamed
RewriteBase /pro/

# Change the '/pro/' portion of the condition if directory is renamed 
RewriteCond %{REQUEST_URI} ^/pro/admin(.+)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ admin/index.php?url=$1 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Run Code Online (Sandbox Code Playgroud)