Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Use mod_rewrite to redirect from a bad URL

Posted on 2012-03-30
4
Medium Priority
?
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 14

Accepted Solution

by:
EMB01 earned 1400 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 600 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…
Suggested Courses

647 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