.htaccess 漂亮的url不起作用
下面是我的.htaccess 漂亮的url不起作用,.htaccess,yii2,friendly-url,yii2-advanced-app,.htaccess,Yii2,Friendly Url,Yii2 Advanced App,下面是我的main.php 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ '<controller:\w+>/<id:\d+>' => '<controller>/view', '<controller:\
main.php
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [ '<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
],
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [ '<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
],
],
“urlManager”=>[
“enablePrettyUrl”=>true,
'showScriptName'=>false,
'规则'=>['/'=>'/view',
'//' => '/',
'/' => '/',
],
],
我已经启用了漂亮的url(我想),我得到了很多404,比如
192.168.1.3/~user/urshow/frontend/web/movies/movies\u all
如果它是这样的话,它会工作得很好192.168.1.3/~user/urshow/frontend/web/index.php?r=movies/movies\u all
而且没有任何链接是工作的完美之前 我认为这会奏效
192.168.1.3/~user/urshow/frontend/web/index.php/movies/movies_all
将此代码放入common/config/main.php
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [ '<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
],
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [ '<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
],
],
'urlManager'=>[
“enablePrettyUrl”=>true,
'showScriptName'=>false,
'规则'=>['/'=>'/view',
'//' => '/',
'/' => '/',
],
],
试试这个。。。
在根文件夹中创建.htaccess
文件
并添加以下代码
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)
RewriteRule ^(.+)$ index.php?$1 [PT,L,QSA]
可能会帮助您..创建.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
现在,在web.php的组件部分添加以下内容:
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],
'urlManager'=>[
'class'=>'yii\web\UrlManager',
//禁用index.php
'showScriptName'=>false,
//禁用r=路由
“enablePrettyUrl”=>true,
'规则'=>数组(
“/”=>“/视图”,
'//' => '/',
'/' => '/',
),
],
这肯定会起作用。我的.htacess文件位于我的项目的web文件夹中
RewriteEngine on
RewriteBase /~user/urshow/frontend/web/
# 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
配置文件中的my main.php文件
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],
“urlManager”=>[
'class'=>'yii\web\UrlManager',
“enablePrettyUrl”=>true,
'showScriptName'=>false,
'规则'=>数组(
“/”=>“/视图”,
'//' => '/',
'/' => '/',
),
],
这对我很有用。在路由器配置中添加下面的语句,以实现html5
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
然后在web.config上添加设置
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="AngularJS" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
我试过了,但没有成功。我在控制台中遇到了很多错误,比如-GET 404(未找到)2:12 GET 404(未找到)2:30您在url前端之前使用了~user和urshow,您确定它与route(r=)一起工作吗??我的意思是,正如我所知,yii2中的url类似于-localhostaddress/projectName/backendOrFrontend/web/index.php-对不起,我的工作url是-192.168.1.3/~user/urshow/frontend/web/index.php?r=movies/movies\u allsorry:),我不知道如何解决您的问题:)我同意,这应该有效,尽管.htaccess文件不应该放在项目文件夹中,而是放在应用程序的web/文件夹中,index.php文件不在其中工作。我遇到类似这样的错误-无法解析请求~user/urshow/frontend/web/movies/movies\u all您将.htaccess文件放在了哪里?我将其放在了urshow文件夹(我的应用程序文件夹)中。我遇到了类似这样的错误,无法解析请求“~user/urshow/frontend/web/movies/movies\u all”。如果将index.php放在/web之后,它就会工作。它只是“index.php”,不起作用。用.htaccess文件重写规则的最后一行替换它^(.+)$index.php?$1[PT,L,QSA]希望这一切顺利