0

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?

enter image description here

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.

4
  • Does your urls get generated properly? Or application redirects you to index.php? Commented Oct 18, 2013 at 11:10
  • @PeterM: my browser says http://localhost/trackstar/project but I'm on the index.php page. Commented Oct 21, 2013 at 6:37
  • Is .htaccess located in the same directory with index.php? Commented Oct 21, 2013 at 7:40
  • @CreatoR: Yes, in www\Trackstar, there is another .htaccess file located in www\Trackstar\protected with contents deny from all. Commented Oct 21, 2013 at 11:30

4 Answers 4

1

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,
),
Sign up to request clarification or add additional context in comments.

2 Comments

No changes, still being redirected to index.php.
Same result, redirect to index.php
0

You can do that with 2 simple steps.

  1. Configure the 'urlManager' at config/main.php to look like this

            'urlManager'=>array(
                'urlFormat'=>'path',
                'showScriptName'=>false,      
            ),
    
  2. 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!

Comments

0

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]

11 Comments

Thanks, but still doesn't work; http://localhost/trackstar/index.php/project still works; http://localhost/trackstar/project redirects to localhost (not even project root)
changed order of rule, can you try now.
Hmm, same result, a redirect to localhost.
With your last edit, I'm now being redirected to index.php.
So a URI like http://localhost/trackstar/index.php is not becoming http://localhost/trackstar/?
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.