我的Web应用程序中有url模式,例如“ www.mysitename.com/foldername/controller/method”。
并且所有请求的页面都首先在根文件夹上重定向到index.php,然后处理请求的页面。
但是每当我转到管理面板(www.mysitename.com/admin)时,URL都会将“ admin”作为文件夹名称,并且它向我显示admin的index.php(以这种方式很正常),然后使用controllername或methodname,它不会通过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]

最佳答案

您的管理目录中是否有一个.htaccess文件,或者根目录中只有一个文件?每个目录中必须有一个。

我刚刚用.htaccess中的/htdocs/pro.htaccess中的相同/htdocs/pro/admin进行了测试,它的工作原理与您解释的完全相同。

/htdocs/pro/.htaccess中的htaccess根目录

Options -Indexes
RewriteEngine on

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

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


/htdocs/pro/admin/.htaccess中的管理员htaccess

Options -Indexes
RewriteEngine on

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

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


/htdocs/.htaccess/htdocs/pro/.htaccess中的单个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]

关于php - htaccess管理面板的重写规则,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15001934/

10-12 01:05
查看更多