我的项目网址是 http://localhost/starmaker/admin
站点工作正常,但是当我在网址中添加一个额外的斜杠时,它将站点重定向到本地主机
像这样 http://localhost/starmaker/admin/(我在管理员后添加了一个斜杠),然后按Enter键
我希望网址应为 http://localhost/starmaker/admin
.htaccess和index.php放置在根目录中,而不是公共文件夹中
成功代码
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ index.php [L]
</IfModule>
# Disable Directory listing
Options -Indexes
# block files which needs to be hidden // in here specify .example extension of the file
<Files ~ "\.(env|json|config.js|md|gitignore|gitattributes|lock|example)$">
Order allow,deny
Deny from all
</Files>
# in here specify full file name sperator '|'
<Files ~ "(artisan)$">
Order allow,deny
Deny from all
</Files>
路由代码
Route::get('/', function () {
$login_user_id = \Session::get('id');
if (isset($login_user_id) || $login_user_id != "") {
Redirect::to('user/profile')->send();
}
else {
return View::make('frontend.welcome');
}
});
Route::get('admin', function () {
return View::make('backend.adminlogin');
});
Route::controller('admin', 'adminController');
答案 0 :(得分:0)
您必须对公共目录中的.htaccess
文件进行一些更改
找到以下几行
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
并删除它们或在开头添加哈希#
,如下所示。
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} (.+)/$
#RewriteRule ^ %1 [L,R=301]