Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-05-2011, 07:27 PM   PM User | #1
Manny89
New to the CF scene

 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Manny89 is an unknown quantity at this point
Smile .htaccess Redirection Error

I'm currently reconfiguring my web server and as part of it, I need to move some files around the server.

Currently, I am using the following URL:

http://www.domain.com/directory

The directory being called in the URL is a subdirectory of the root public_html directory. Now, I am going to be hosting multiple sites on the server and have created a 'websites' directory inside the root. The directory that was previously called in the URL has been moved into the 'websites' directory.

As the directory has been moved, the URL would now have to read:

http://www.domain.com/websites/directory

What I want to do is use .htaccess to ensure the old URL remains live and anybody using the second URL is automatically redirected.

Inside my root directory, I have the following code inside a .htaccess file.

Code:
# Ensure the URL ends with a trailing slash
RewriteRule ^directory$ http://www.domain.com/directory/ [R=301,L]

# Rewrite the URL to grab the contents from the websites directory
RewriteRule ^directory/(.*)$ /websites/directory/$1 [L]
Then, inside the 'websites' directory, I have the following lines in another .htaccess file

Code:
RewriteRule ^directory$ http://www.domain.com/directory/ [R=301,L]
Now this is all working fine, with one exception.

http://www.domain.com/websites/directory (no trailing slash) works absolutely fine and redirects to http://www.domain.com/directory/

However, http://www.domain.com/webites/directory/ (with trailing slash) does not redirect.

I have also tried changing the .htaccess code in the 'websites' directory, as follows:

Code:
# Make trailing slash optional
RewriteRule ^directory/?$ http://www.domain.com/directory/ [R=301,L]
This redirects as intended, but then a redirection error appears across all browsers. If this error can be resolved, then the intended solution would be working perfectly. What am I doing wrong?
Manny89 is offline   Reply With Quote
Old 12-06-2011, 02:58 PM   PM User | #2
Manny89
New to the CF scene

 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Manny89 is an unknown quantity at this point
Apologies for double posting. Having read back through my original post, I realise it's a little long winded so I'll try to cut it down.

Basically, the current URL of my site would be:
http://www.domain.com/websites/directory

Using .htaccess, I can rewrite the URL to leave out 'websites' and leave the URL as follows:
http://www.domain.com/directory

However, if the user enters the first URL, I want to redirect them to the second. The aim is to redirect people to the second URL without the redirection error that appears.

I would also like the trailing slash at the end of the URL to be forced.
Manny89 is offline   Reply With Quote
Old 12-07-2011, 01:44 AM   PM User | #3
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Try something like this:
Code:
# Ensure the URL ends with a trailing slash
RewriteRule ^directory$ http://www.domain.com/directory/ [R=301,L]

# Rewrite the URL to grab the contents from the websites directory
RewriteRule ^directory/(.*)$ /websites/directory/$1 [L]

# Redirect /website directories
RewriteRule ^websites/(.*)$ http://www.domain.com/$1/ [R=301,L]
Not tested.
Inigoesdr is offline   Reply With Quote
Old 12-07-2011, 04:22 AM   PM User | #4
zabalex
New Coder

 
Join Date: Oct 2011
Location: San Francisco, CA
Posts: 20
Thanks: 0
Thanked 1 Time in 1 Post
zabalex is an unknown quantity at this point
Try this

Code:
Redirect 301 /directory/ http://www.domain.com/websites/directory/
tested for directory level redirection but not sure in your case it will work or not. it should be placed in the .htaccess of root.
__________________
Search Engine Optimization, San Francisco Internet Marketing
SEO Bay Area |AND| Custom Website Design
zabalex is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:05 AM.


Advertisement
Log in to turn off these ads.