# Solved: .htaccess redirect loop problem.



## firestormer

I need to redirect all requests for files in the directory /webb/ to /webb/pages/ using .htaccess

Ive tried doing this:
Redirect /webb/ http://www.mysite.org.uk/webb/pages/

but this just results in an infinte redirect loop.

im using a cms which stores the pages in the dir pages. but i want my users to be able to type in http://www.mysite.org.uk/contact.php and not http://www.mysite.org.uk/pages/contact.php

is there a way to refine the command?


----------



## MMJ

Post your .htaccess code.


----------



## firestormer

err i have, but here it is again



Code:


redirect /webb/ http://www.mysite.org.uk/webb/pages/

#

The loop ocures because it is applied to sub dir as well.

Currently the server dosn't seem to have mod rewite enable but i've sent a email asking them about it.


----------



## tomdkat

Is that line the ONLY line in your htaccess file?

Peace...


----------



## firestormer

at the moment yes, i plan to add some errordoc redirects as well.


----------



## MMJ

firestormer said:


> err i have, but here it is again


Hmm... where exactly did you post it?

try redirect http://www.mysite.org.uk/webb/ http://www.mysite.org.uk/webb/pages/


----------



## tomdkat

MMJ said:


> Hmm... where exactly did you post it?


In his first post. 

Peace...


----------



## MMJ

tomdkat said:


> In his first post.
> 
> Peace...


I skim too fast


----------



## tomdkat

MMJ said:


> I skim too fast


It's ok. He didn't indicate he posted the complete htaccess file in his first post, which is why I asked for confirmation above. It looks like he tried your suggestion already and it's not working. I have a similar need that I haven't gotten resolved either. 

Peace...


----------



## firestormer

Sorry for the delay, i've been in wales doing a bit of canoe surfing, it was my first time and it is fantastic.

right.

Ive found this code
http://www.bluehostforum.com/showthread.php?t=402


Code:


# Turn on rewrites.
RewriteEngine on

# Only apply to URLs on this domain
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$

# Only apply to URLs that aren't already under folder.
RewriteCond %{REQUEST_URI} !^/folder/

# Don't apply to URLs that go to existing files or folders.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all those to insert /folder.
RewriteRule ^(.*)$ /folder/$1

# Also redirect the root folder.
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ folder/index.php [L]

Which works but only for the root directory, so for example when the user types:
www.mysite.com
they actualy get www.mysite.com/folder but with www.mysite.com showing in the address bar.

but it dosn't work for what i want which is for a user to type www.mysite.com/folder and get www.mysite.com/folder/subfolder but with www.mysite.com/folder showing in the address bar.


----------



## firestormer

Ok ive been trawling the web and ive made this which works!



Code:


ErrorDocument 404 /test/webb/pages/404-not-found.php

RewriteEngine on
RewriteOptions MaxRedirects=2



RewriteRule ^test/webb/$ test/webb/index.php [L]
RewriteRule ^test/$ test/webb/index.php [L]
RewriteRule ^test/([^/\.]+)/?$ /test/webb/pages/$1.php [L]
RewriteRule ^test/([^/\.]+)/([^/\.]+)/?$ /test/webb/pages/$1/$2.php [L]
RewriteRule ^test/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /test/webb/pages/$1/$2/$3.php [L]
RewriteRule ^test/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /test/webb/pages/$1/$2/$3/$4.php [L]

Im still refining it. I'd like it to tidy up addresses more, so that if a user actually enters 
test/webb/pages/apage.php the browser would show /test/apage or
test/webb/pages/dir/apage.php the browser would show /test/dir/apage


----------

