Reputation: 69
my code runs with url:
http://localhost/yii/index.php/Adminlogin
I want url to look like:
http://localhost/yii/Adminlogin
.htaccess file
Options +FollowSymLinks
IndexIgnore */*
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
main.php
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'redirect/<redirectUrl>'=>'site/index',
'login'=>'site/login',
'privacy'=>'site/privacy',
'password'=>'site/forgot',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
Upvotes: 0
Views: 1042
Reputation: 414
my htaccess would look like
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
and in main.php
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'caseSensitive'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
Upvotes: 0
Reputation: 21620
Also, ... remember to AllowOverride
in your main apache configuration:
<Directory "/path/to/your/yii.sample/web/">
Options FollowSymLinks Multiviews
MultiviewsMatch Any
AllowOverride All
Require all granted
allow from all
</Directory>
Is it possible that your web/.htaccess
is correct, but your apache never allowed your
Upvotes: 0
Reputation: 516
Try this
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php(.*) [NC]
RewriteRule ^(.*)index\.php(.*)$ http://%{HTTP_HOST}$1/$2 [R=301,L]
or
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php(.*) [NC]
RewriteRule ^index\.php(.*)$ http://%{HTTP_HOST}$1 [R=301,L]
Upvotes: 0
Reputation: 250
Use this in your main.php
'urlFormat'=>'path',
'showScriptName'=>false,
And in your htaccess use below,
RewriteRule ^(.+)$ index.php?$1 [PT,L,QSA]
Upvotes: 1