Solved

Use mod_rewrite to redirect from a bad URL

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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 …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

747 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

10 Experts available now in Live!

Get 1:1 Help Now