Reputation: 651
In my test application, I'm trying to remove index.php
from the url. I can access the root page like so http://localhost/trackstar/
instead of http://localhost/trackstar/index.php
, but as soon as I'm trying to access another page like http://localhost/trackstar/project
or any other page I'm always ending up at the index.php
page. Opening http://localhost/trackstar/index.php/project
works however.
I'm using WAMP server. Configuration as below.
Rewrite module in apache is enabled.
Config main
:
'urlManager' => array(
'urlFormat' => 'path',
'rules' => array(
'commentfeed' => array('comment/feed', 'urlSuffix' => '.xml', 'caseSensitive' => false),
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
'showScriptName' => false,
),
.htaccess
in root folder of project:
Options +FollowSymlinks
IndexIgnore */*
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
I've also added in httpd.conf
, although not really necessary I think:
<Directory "c:/wamp/www/TrackStar/">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
I've tried several combinations of extra parameters in .htaccess
, but I keep getting redirected to my index.php
page.
Any thoughts as to why this doesn't work?
Edit:
Since I'm being redirected, the checks in RewriteCond
don't succeed, in other words the REQUEST_FILENAME
isn't found as a directory or file. Maybe there's something off in my directory structure?
The TrackStar\protected\views\project
directory, for example is the page I'm trying to access via http://localhost/trackstar/project
. My Yii
framework files are in a directory above the www
folder.
Upvotes: 0
Views: 3433
Reputation: 11
change your config/main.php like below:
'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>',
),
then place your htaccess file on base directory with protected folder (it may be inside protected folder) place below code to your htaccess file
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
or try with this---
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]
done...hope it will work
Upvotes: 0
Reputation: 1652
Try to add into .htaccess following after RewriteEngine on
:
RewriteBase /trackstar/
The problem in: when not found file it redirects to http://localhost/index.php
, in request http://localhost/trackstar/index.php/project
file index.php
is found and it works correctly
UPDATED:
Try modify your urlManager settings (add /trackstar/
):
'urlManager' => array( 'urlFormat' => 'path', 'rules' => array( 'commentfeed' => array('comment/feed', 'urlSuffix' => '.xml', 'caseSensitive' => false), '/trackstar/<controller:\w+>/<id:\d+>' => '<controller>/view', '/trackstar/<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', '/trackstar/<controller:\w+>/<action:\w+>' => '<controller>/<action>', ), 'showScriptName' => false, ),
Upvotes: 1
Reputation: 786349
Can you try:
.htaccess in root folder of project:
Options +FollowSymlinks -MultiViews
IndexIgnore */*
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.*?)index\.php$ /$1 [L,NC,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Upvotes: 0
Reputation: 2188
You can do that with 2 simple steps.
Configure the 'urlManager' at config/main.php to look like this
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
),
Add an .htaccess file at the root of the application with the following code
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
Thats it!
Upvotes: 0