mod_rewrite - how to catch old links and redirect ?

Posted on 2012-08-20
Medium Priority
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://www.myhost.com/html_files/safari/buy_tickets.html

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
  • 3
  • 2
LVL 49

Expert Comment

ID: 38310933

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

ID: 38311044
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

Roonaan earned 1500 total points
ID: 38311100
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

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

Author Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

What You Need to Know when Searching for a Webhost Provider
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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 …
Suggested Courses
Course of the Month16 days, 13 hours left to enroll

862 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