0
votes

I have a yii website under a sub directory e.g

http://localhost/~username/maindirectory/yiiapp/

My htaccess file:

DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks
IndexIgnore */*
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /yiiapp

# 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
</IfModule>

protected/config/main.php

...
'urlManager'=>array(
    'urlFormat'=>'path',
    'showScriptName'=>false,
....

The issue:

let say I accesss :

  • step one: http://localhost/~username/maindirectory/yiiapp/
  • step two: click any link on home page (default yii app) let say About Us page
  • step three: http://localhost/~username/maindirectory/yiiapp/site/page?view=about
  • step four : click on any on the link (let say same page)
  • url will look like : http://localhost/yiiapp/site/page?view=about

so : all links are accessible as : http://localhost/yiiapp/.... , instead of removing index.php from link the while string b/w localhost and base directory is removed .

I tried this already and need the same sort of url on localhost , obviously without using sub domains

please help me fix this .

3

3 Answers

0
votes

Partial answer:

The problem is that you are redirecting to an absolute URL on the same domain.
The URL probably looks like /yiiapp/site/page?view=about. However that leads to http://localhost/yiiapp/site/page?view=about. You must prepend the website directory relative to the domain (not sure if I expressed properly).

For example, the URL in the a href tag should look like /~username/maindirectory/yiiapp/site/page?view=about so you must prepend the /~username/maindirectory part from somewhere.

0
votes

Have your tried:

'urlManager'=>array(
    ....
    'baseUrl' => '/~username/maindirectory/yiiapp',
    ....

http://www.yiiframework.com/doc/api/1.1/CUrlManager#setBaseUrl-detail

0
votes

so RewriteBase /~username/maindir/yiiapp , in .htaccess fixed the issue , not the 'baseUrl' => '/~username/maindirectory/yiiapp' thing in config/main.php

Here is the full .htaccess file:

DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks
IndexIgnore */*
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /~username/maindir/yiiapp

# 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
</IfModule>