Solved

Use mod_rewrite to redirect from a bad URL

Posted on 2012-03-30
4
273 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

Free camera licenses with purchase of My Cloud NAS

Milestone Arcus software is compatible with thousands of industry-leading cameras for added flexibility. Upon installation on your My Cloud NAS, you will receive two (2) camera licenses already enabled in the software. And for a limited time, get additional camera licenses FREE.

Question has a verified solution.

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

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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…
The viewer will learn how to dynamically set the form action using jQuery.
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…

929 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now