We help IT Professionals succeed at work.

htaccess page redirect

Robert Granlund
Robert Granlund asked
on
I want to redirect a page on my website using  a htaccess file. I want everything in the insight directory, no matter what type of page or folder contained in the folder to redirect.  I don not belive I have written my htaccess file correct.  This is what I have so far:

redirect http://www.MYSIGHT.com/insight/ http://dev.MYSITE.com/index.php/practice/listings/

Open in new window

Comment
Watch Question

Top Expert 2011

Commented:
Try placing this htaccess file in the insight directory.
You'll want to change the value of "NewLocationHere"

Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^insight(.*)$ http://www.MYSIGHT.com/NewLocationHere$1 [L,R=301]

</IfModule>

Open in new window

Author

Commented:
That works ok, but not all the way.

if I type in www.MYSITE,com/insight/index.php
the redirect should send it to:
 http://dev.MYSITE.com/index.php/practice/listings/
but right now it sends it to:
 http://dev.MYSITE.com/index.php/practice/listings/index.php/

In the new folder there is NOT an index.php, I have an index.html
It also adds a backslash to the very end that I don't won't.

This is what I have so far:

RewriteRule ^insight(.*)$ http://www.MYSITE.com/index.php/practice_career/od-listings

Open in new window

Top Expert 2011
Commented:
Sorry bout that... remove the $1 from the new location

Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^insight(.*)$ http://www.MYSIGHT.com/NewLocationHere [L,R=301]

</IfModule>

Open in new window

Top Expert 2011

Commented:
Looks like the only real difference between what you have and my code is that I included "[L,R=301]" at the end which tells the browser that it is a 301 redirect.

Please post a couple examples of what does and does not work with your current rule so I can get a feel for what might be missing...

e.g.,
subdirectory redirects:  /insight/folder1/page.php redirecting to "..."
page redirects:  /insight/index.php redirecting to "..."
and any others that may not be working right

Author

Commented:
It is re-directing the folder fine, but it is holding onto everything after the folder redirect and tacking it on to the end of the new url.
Top Expert 2011

Commented:
It is including the page and subfolder names even after removing the $1 from the redirect?

Author

Commented:
yes it is.