Solved

htaccess Help rewrite  / redirection rules

Posted on 2012-03-27
7
252 Views
Last Modified: 2012-04-17
Hi All

We have a simple html website hosted using a 3rd party hosting company.
we created a folder under the root website.

but when we type in

http://www.mywebsite.com.au/foldername it does not automatically redirect to http://www.mywebsite.com.au/foldername/ hence it gives us page not found error.

i was told by out web hosting company that this could be done via the htaccess

Could anyone please suggest what should i use for this purpose?
i tried redirect and rewrite rules but none seems to be working

my rewrite are as follows:

RewriteEngine on
RewriteRule ^/foldername$ foldername/ [NC,L]

is there anything missing here?
0
Comment
Question by:BCSITS
  • 3
  • 3
7 Comments
 
LVL 6

Expert Comment

by:HAVARD7979
ID: 37777150
Why not use HTML redirect code:
<HTML>
<HEAD>
<meta http-equiv="refresh" content="2; URL=http://www.mywebsite.com.au/foldername">
</HEAD>
<BODY>
Waiting.........
</BODY>
</HTML>
Save as index.htm and upload to root dir

or for .htaccess

RedirectMatch permanent ^/$ http://www.mywebsite.com.au/foldername/index.htm

or

Redirect permanent / http://www.mywebsite.com.au/foldername
0
 

Author Comment

by:BCSITS
ID: 37779479
Hi All

Thanks for the suggestion.
However the html redirect suggestion. we wont be able to do because there is actually a main page in there called index.html that is hosting a running website.

my apologies for not mentioning this before but we actually have 2 folders
so for in this instance i would like to redirect

http://www.mywebsite.com.au/folder1 ===> http://www.mywebsite.com.au/folder1/
http://www.mywebsite.com.au/folder2 ===> http://www.mywebsite.com.au/folder2/

I tried .htaccess method using permanent and just Redirect, but none of it actually works.
The Redirect permanent gives us Internal Server Error 500 and the Redirect method does
not work aswell

Redirect permanent /folder1 http://www.mywebsite.com.au/folder1/
Redirect permanent /folder2 http://www.mywebsite.com.au/folder2/

Open in new window


Redirect /folder1 http://www.mywebsite.com.au/folder1/
Redirect /folder2 http://www.mywebsite.com.au/folder2/

Open in new window


Please help
0
 
LVL 6

Expert Comment

by:HAVARD7979
ID: 37781431
Who is your hosting company.  if they have cpanel you can set up a subdomain.  
it would be http://folder1.mywebsite.com.au instead of http://www.mywebsite.com.au/folder1 

even if you do not have a cpanel the hosting company should be able to set up the sub-domain for you.  I do this all the time where we have a regular website and a estore.  you an look at http://aaefe.org   and http://jle.aaefe.org     I think it looks better than the folder and if you are on linux server the folder name is case sensitive where the sub-domain is not.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:BCSITS
ID: 37784644
Hi HARVARD

Thanks for the info,

We are hosting through Melbourne IT
I know about the sub domain, but marketing specifically want to have
http://www.mywebsite.com.au/folder1 format not the sub domain.

I checked their console and asked their support they are not helpful at all.
they referred me to the htaccess and when I asked for assistance they send me the htaccess manual from Apache.org website.

Can someone help?
0
 
LVL 6

Expert Comment

by:HAVARD7979
ID: 37787320
the redirect should work have you tried

redirect http://www.mywebsite.com.au/folder1 http://www.mywebsite.com.au/folder1/

you need the full path on the first part.

I do not like them because Apache is famous for over writing the .htaccess on updates etc.
0
 
LVL 26

Accepted Solution

by:
arober11 earned 500 total points
ID: 37848873
Hi

The issue with your original RewriteRule is that your using the httpd.conf rather than .htaccess syntax, a quick shuffle of a "/" and the following should work, in your .htaccess file:

RewriteEngine on
RewriteRule ^foldername$ /foldername/ [NC,L]
0
 

Author Comment

by:BCSITS
ID: 37849478
Hi Arober11

Thanks !!! that seems to have taken me one step closer.
but now when I type in

www.mywebsite.com/folder1

the rule seems to be taking out the "www" bit and it becomes

mywebsite.com/folder1/

how can i retain the www?
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Weird Samba Connectivity Issue... 7 40
Backup & Restore 3 55
Can't ping New Linux Servers 40 66
Quickest way to query Windows Event ID from a Linux Device 3 31
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question