Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用.htaccess在Yii2框架中创建干净的URL?_Php_Apache_.htaccess_Mod Rewrite_Yii2 - Fatal编程技术网

Php 如何使用.htaccess在Yii2框架中创建干净的URL?

Php 如何使用.htaccess在Yii2框架中创建干净的URL?,php,apache,.htaccess,mod-rewrite,yii2,Php,Apache,.htaccess,Mod Rewrite,Yii2,我正在尝试为我的网站创建一个干净的url,该网站是使用Yii2框架开发的,仅使用.htaccess。我知道我可以使用Yii2的urlmanager类。但由于某些特殊原因,我不能使用它,只想使用.htaccess创建干净的url 我想转换以下url: Url=“” 到 Url=“” 提前感谢。首先,您必须更改yii2应用程序配置中的urlManager组件: 'urlManager' => [ 'enablePrettyUrl' => true, 'showScript

我正在尝试为我的网站创建一个干净的url,该网站是使用Yii2框架开发的,仅使用.htaccess。我知道我可以使用Yii2的urlmanager类。但由于某些特殊原因,我不能使用它,只想使用.htaccess创建干净的url

我想转换以下url: Url=“” 到 Url=“”


提前感谢。

首先,您必须更改yii2应用程序配置中的urlManager组件:

'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
]
showScriptName将从URL格式中删除index.php

enablePrettyUrl将提供漂亮的URL格式,如“您想要的”)

其次,您需要在主机配置中设置URL重写规则。.htaccess(Apache)的示例:


您可以在

中阅读更多信息,甚至从未尝试过这样做,但您只需要一个控制器?不,我想为所有控制器执行此操作。然后您显然需要使用localhost:8090/site/contact。但只要您不能编辑yii文件,这就不是yii问题。尝试阅读apache.htaccess文档。
RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php