Yii Framework Forum: Mod rewrite for removing a folder name from URL - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Mod rewrite for removing a folder name from URL Possible? and How to approach? Rate Topic: -----

#1 User is offline   zyphers 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 04-March 10

Posted 08 August 2011 - 06:11 AM

Dear guys,

What I tried to do is to remove a folder from URL.
For example www.example.com/app into www.example.com.

Seems not a big deal but... let see details.

My Problem details
1. I create a new web app from command line like in the first yii app steps. (I named the web app folder as "htdocs" instead of "testdrive")

So let say the base folder of this whole application is /var/www/myapp/.
With these folders inside.

/framework/
/htdocs/

(/requirements/ removed)


2. For URL bountifulness's sake remove index.php from URL using index.php hidding with url manager. This works fine.

3. For security's sake, I move "protected" folder out from "htdocs".

So, now it becomes.

/framework/
/htdocs/
/protected/


And I use apache to create virtual host for my web site and set www.example.com to point to /var/www/myapp/.
It would be easy if I just create virtual host and point to /var/www/myapp/htdocs/. But no I can't, I can't touch the server setting.

So when I run my application it will be like www.example.com/htdocs/ so .. I want to remove those /htdocs/.

.htaccess that I used
Up until now I used 2 .htaccess

1. Located at base folder
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    ^$ htdocs/    [L]
RewriteRule    (.*) htdocs/$1 [L]


2. Located inside /htdocs/
RewriteEngine on
# forward everything to index.php
RewriteRule . index.php


By doing this /htdocs/ always appear in the URL, so what should I do the remove the folder in URL.
Thanks in advance :)
0

#2 User is offline   Soumya 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 21-November 10
  • Location:Kolkata, India

Posted 08 August 2011 - 07:20 AM

You can try the following code
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /htdocs/

# 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 [L]

</IfModule>

0

#3 User is offline   zyphers 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 04-March 10

Posted 08 August 2011 - 10:39 PM

View PostSoumya, on 08 August 2011 - 07:20 AM, said:

You can try the following code
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /htdocs/

# 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 [L]

</IfModule>




Thanks, I will. I guess I should put this in /htdocs/ right? Anyway I'll try :)
0

#4 User is offline   germanliu 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 26-September 12

Posted 13 July 2013 - 01:22 PM

Hi, have you resolved this? I have the same problem.

Thanks
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users