Welcome Guest, Not a member yet? Register   Sign In
.htaccess with subfolder as root
#1

[eluser]elaniobro[/eluser]
I've looked over the forum, but have yet to see a solution, or perhaps I just did not read the thread title correctly, or the body of said thread did not pertain 100% to my issues.

Let me explain:

I am currently using .htaccess on my site to versionize my site. So for instance the first iteration of my site lies in:
http://www.example.com/1 Where /1 is the root directory.

I am currently working on /5 and would like to make this the root site.

so, I can currently navigate to:
http:://www.example.com/5/index.php/home

I would like it to be:
http:://www.example.com/home

Let me share with you what my current .htaccess file looks like:


Code:
Options +FollowSymLinks
RewriteEngine On
AddType x-mapp-php5 .php

    
#declares the base from which to start the rewrite
    RewriteBase /

#sets the folder in which to make the 'base'
    RewriteCond %{REQUEST_URI}  !(thoughts)
    RewriteRule ^thoughts/(.*)$ thoughts/$1/ [L]

#allows direct access to this directory
    RewriteCond %{REQUEST_URI}  !(staging/0)
    RewriteRule ^staging/(.*)$ staging/0/$1/ [L]

#allows direct access to this directory
    RewriteCond %{REQUEST_URI}  !(mydomain2)
    RewriteRule ^mydomain2(.*)$ mydomain2/$1/ [L]
    
#sets the conditions.
    RewriteCond %{REQUEST_URI}  ^/{*} #note ^/{*} remove brackets around asterisk, CI forum does not allow '/*'
    RewriteCond %{REQUEST_URI}  !(0|1|2|5|staging/0|thoughts|pixels|mobile|mydomain2)
    RewriteRule ^(.*)$ thoughts/$1 [L,NC]

#custom error pages.
    errorDocument 400 /error/400.html
    errorDocument 401 /error/401.html
    errorDocument 403 /error/403.html
    errorDocument 404 /error/404.html
    #errorDocument 500 /error/500.html
    errorDocument 500 /index.html

*note 'thoughts' is the name of my wordpress blog which is a subdirectory, which I have been using as my main site. Changing it to '5' in all instances works, however when navigating to another page, the /5/ re-appears in the URL
#2

[eluser]skunkbad[/eluser]
If I understand you correctly, all you need to do is adjust the rewrite base.

RewriteBase /whatever/
#3

[eluser]elaniobro[/eluser]
Yea, you would think that would work, but it does not. When I do that I get a 404. Any other suggestions?
#4

[eluser]WanWizard[/eluser]
Enable rewrite logging (RewriteLogLevel 9), and check step by step what the rewrite engine is doing...
#5

[eluser]elaniobro[/eluser]
This is hosted at 1and1.com, I am rather new to this, so I do not know how to enable rerwrite log, nor where to find it on the server.
#6

[eluser]WanWizard[/eluser]
Ah, sorry, can't help you there, I run my own servers.

Don't you have an offline development environment that is setup equal to production, so you can test stuff before you make it live? That would come in very handy in situations like this...
#7

[eluser]danmontgomery[/eluser]
That's not really what mod_rewrite is for... Use mod_alias:

Code:
Alias / /5

edit:

You'll also have to add the passthrough flag to your rewrite rules, so [L] becomes [PT,L], [L,NC] becomes [PT,L,NC]
#8

[eluser]elaniobro[/eluser]
-WanWizard

I do have a local enviroment set up using MAMP, have yet to configure it to work with .htaccess

-Noctrum

Could you elaborate? I have never seen nor heard of 'Alias' in .htaccess file. How would you use it?
#9

[eluser]elaniobro[/eluser]
I was able to get this working in MAMP with the following .htaccess code:

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    #RewriteBase /
    RewriteBase /5
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    #RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

However, when I put it live, this is not working at all.. Very frustrating...
#10

[eluser]skunkbad[/eluser]
Did you try putting the question mark after index.php? Dreamhost, Godaddy, and some other servers require this for some reason. Look here in the forum, and you will see this usage.




Theme © iAndrew 2016 - Forum software by © MyBB