1. 云栖社区>
  2. PHP教程>
  3. 正文

[Wiki] Easy way to redirect http://localhost/yii2-basic to http://localhost/yii2-basic/web/...

作者:用户 来源:互联网 时间:2017-12-01 17:09:34

localhost

[Wiki] Easy way to redirect http://localhost/yii2-basic to http://localhost/yii2-basic/web/... - 摘要: 本文讲的是[Wiki] Easy way to redirect http://localhost/yii2-basic to http://localhost/yii2-basic/web/..., First of all, install yii2 basic template according below link: How to install yii2 basic template Then, normaill you h

First of all, install yii2 basic template according below link:

How to install yii2 basic template

Then, normaill you have to use http:/localhost/yii2-basic/web to launch your homepage.And our target is both http:/localhost/yii2-basic and http:/localhost/yii2-basic/web can launch your home page.

Steps:

1. Create .htacess file **bothin your localhost/yii2-basic and localhost/yii2-basic/web folder ** the .htacss file look like below (which I copy from Kartik template:)

# ----------------------------------------------------------------------# Adds some security for the Apache server configuration for use with# ---------------------------------------------------------------------- # "-Indexes" will have Apache block users from browsing folders without a default document# Usually you should leave this activated, because you shouldn't allow everybody to surf through# every folder on your server (which includes rather private places like CMS system folders).<IfModule mod_autoindex.c>Options -Indexes</IfModule># Block access to "hidden" directories whose names begin with a period. This# includes directories used by version control systems such as Subversion or Git.<IfModule mod_rewrite.c>RewriteCond %{SCRIPT_FILENAME} -dRewriteCond %{SCRIPT_FILENAME} -fRewriteRule "(^|/)/." - [F]</IfModule># Block access to backup and source files# This files may be left by some text/html editors and# pose a great security danger, when someone can access them<FilesMatch "(/.(bak|config|sql|fla|psd|ini|log|sh|inc|swp|dist)|~)$">Order allow,denyDeny from allSatisfy All</FilesMatch> # Increase cookie security<IfModule php5_module>php_value session.cookie_httponly true</IfModule> # Settings to hide index.php and ensure pretty urlsRewriteEngine on # if a directory or a file exists, use it directlyRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d # otherwise forward it to index.phpRewriteRule . index.php

2.Create another index.php in your localhosts/yii2-basic folder.

<?phpheader("location: /yii2-basic/web/");?>

That's all.

In addition, you can use beautiful url too:Step:Add

'urlManager' => ['enablePrettyUrl' => true,'showScriptName' => false,],

into your config array which locate atlocalhost/yii2-basic/config/web.php

以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索localhost ,以便于您获取更多的相关知识。