Solved

Use mod_rewrite to redirect from a bad URL

Posted on 2012-03-30
4
275 Views
Last Modified: 2012-03-31
Some people are tweeting a messed-up URL to my site: http://www.mysite.org/folder/index.html.

The folder and the page don't even exist on my site.

Is it possible to use mod_rewrite to point their messed-up URL to the correct place?
0
Comment
Question by:Dbast
4 Comments
 
LVL 14

Accepted Solution

by:
EMB01 earned 350 total points
ID: 37789636
I would instead use PHP to put an index.php file at http://www.mysite.org/folder/index.php and put this in it:

<?php

// redirect
header("Location: http://www.myCorrectWebsiteAddress.com");

?>
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37789640
what are the "messed-up" URLs, and what is the "correct place"?
Do you want to redirect specific requests to another location, or ALL of the traffic that request a non-existing resource?
0
 
LVL 2

Assisted Solution

by:BillAndras
BillAndras earned 150 total points
ID: 37790606
Yes, in your httpd.conf or .htaccess file turn the rewrite module on:

RewriteEngine  on

Then add the following rewrite rule:
RewriteRule    ^/folder/index.html http://www.mysite.org/realpage/index.html  [NC, R, L]

Or
RewriteRule    ^/folder/(.*) http://www.mysite.org/realpage/index.html  [NC, R, L]

First one will catch the exact page they are requesting and send them to the real page. The second one will catch any URI they type in under /folder/ and send them to the new page index. NC = no case, R = rewrite, L = last
0
 

Author Closing Comment

by:Dbast
ID: 37791541
Because the "bad URL" was an index.html, rather than index.php, EMB01's solution didn't quite work, but it absolutely pointed me in the right direction, and using an index.html file with the redirect worked perfectly. I'm sure BillAndras's mod_rewrite solution would have worked as well, but EMB01's was easier for me to implement.

Greatly appreciate the speed with which you all responded!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

776 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