Solved

Use mod_rewrite to redirect from a bad URL

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

861 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