Use mod_rewrite to redirect from a bad URL

Some people are tweeting a messed-up URL to my site:

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?
Who is Participating?
EMB01Connect With a Mentor Commented:
I would instead use PHP to put an index.php file at and put this in it:


// redirect

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?
BillAndrasConnect With a Mentor Commented:
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  [NC, R, L]

RewriteRule    ^/folder/(.*)  [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
DbastAuthor Commented:
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!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.