Link to home
Start Free TrialLog in
Avatar of internetservice_dk
internetservice_dk

asked on

mod_rewrite - how to catch old links and redirect ?

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!
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Hi,

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?

Regards

-r-
Avatar of internetservice_dk
internetservice_dk

ASKER

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
Mark
ASKER CERTIFIED SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Tha fault was not in the .htaccess file - but made me check further!
@Roonaan thanks for the tip, easier to give you the points though :)