mod_rewrite - how to catch old links and redirect ?

Posted on 2012-08-20
Last Modified: 2012-08-20
Hi Experts,

On a site recently developed I've used url rewriting to allow the site to have "nice urls"

Now this works just fine - but I'm also eager to capture any "old" urls - and redirect them to the new site.

So I made a list with all the old URL's and in the db I matched them to the new sites - but today I uploadet everything and all old urls aren't captured, they just get redirected to the / page :(

Here's my .htaccess file
RewriteEngine on
RewriteBase /
# Directories to ignore
RewriteRule ^(assets|inc|cms|css|images|img|admin|js|topimages|video)(/.*)?$ - [L]
RewriteRule ^(index\.php)$ - [L]  
RewriteRule ^(mod_redirect\.php) - [L]
RewriteRule ^(balule_mail\.php) - [L]

RewriteRule ^(.*)(\.html)$ mod_redirect.php?url=$1$2 [L]
RewriteRule ^([^/]*)/([^/]*)/?$     index.php?lang=$1&url=$2  [NC]
RewriteRule ^([^/]*)/?$    index.php?url=$1  [NC]

I thought that the third-last rule would capture all request that ends with .html - but thats not the case it seems...

An url will include numerous folder names etc - I guess this could be the problem ??
An example could be htttp://

Lots of different folders - would like to test if the URL ends with .html and if so, send the request to mod_redirect.php?url=[the complete url]

Can any of you experts help me out, this is really urgent to me :|

Best regards!
Question by:internetservice_dk
    LVL 49

    Expert Comment


    I tried you urls and the provided htaccess script, and it seems to work ok. Is there another .htaccess file on subdirectory that might intervene?

    Has the .htaccess file worked previously with other patterns?



    Author Comment

    Hi Roonaan - thanks for your reply :)

    The .htaccess file ended up working fine - it seems like the problem was coming from a dead database link :/

    Thanks for helping me out!

    Best regards
    LVL 49

    Accepted Solution

    Good to hear that you found the issue!

    Better ask for this question to be closed with refund. Saves you some points to spend.



    Author Closing Comment

    Tha fault was not in the .htaccess file - but made me check further!

    Author Comment

    @Roonaan thanks for the tip, easier to give you the points though :)

    Featured Post

    Superior storage. Superior surveillance.

    WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

    Join & Write a Comment

    In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    734 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

    21 Experts available now in Live!

    Get 1:1 Help Now