News:

LVCS.NET offers low cost domain registration services.

Main Menu

[htaccess] RewriteEngine

Started by Guide, November 13, 2005, 06:15:09 PM

Previous topic - Next topic

Guide

Hello,

I tried to use the .htaccess RewriteEngine in order to forward url's of the type /mylang_mypage.html into the real pages whose name are of the form index.php?lang=mylang&page=mypage.
I used the following .htaccess in the root directory:

QuoteRewriteEngine On

RewriteRule ^(fr|en|es|nl)_([a-zA-Z]*).html /index.php?page=$2&lang=$1
RewriteRule ^index.html$ /index.php

Yet it doesn't word. Does freepgs.com not allow the RewriteEngine, or is my .htaccess wrong? (It did work on the temporary host I took during freepgs' downtime)

webzone (archived)

I am not an expert of mod_rewrite, however I can tell you that the cause of the problem is in your .htaccess because mod_rewrite works perfectly well on freepgs.com and the temporary plesk server.

Guide

That's what I thought ;)
Well, I just hope someone who knows better than I do (which isn't hard) about .htaccess will pass around here...

brainiac744

I'm certainly no expert either, but I THINK I found your problem

RewriteRule ^(fr|en|es|nl)_([a-zA-Z]*).html /index.php?page=$2&lang=$1

That line ^^^^^ is missing a $, it should be this:

RewriteRule ^(fr|en|es|nl)_([a-zA-Z]*).html$ /index.php?page=$2&lang=$1


I THINK...I'm certainly no expert either ;)

Ben

Quote
RewriteEngine On

RewriteRule ^(fr|en|es|nl)_([a-zA-Z]*).html /index.php?page=$2&lang=$1
RewriteRule ^index.html$ /index.php [L]

The differance is the [L] at the end, which signals that it's the last rule.
--Ben
Ben@freepgs.com

Guide

Strange... I just tried both of those advise and it still didn't work. Any other suggestion?
I checked on another computer to be certain it wasn't a cache problem, but still no result but the infamous 404 page. What I find real abnormal is that I get no Server Error, as I usually do when I mess up with the RewriteEngine... Just the Error 404.

webzone (archived)

You only get a Server Error when your .htaccess and/or your RewriteRule are not written properly.

If you only get a 404 error, then it means that your rules can be parsed, but that the address you requested does not match any rewrite instruction (or existing file, of course).

Ben

QuoteRewriteEngine On
RewriteRule ^(fr|en|es|nl)_([a-zA-Z]+).html$ index.php?page=$2&lang=$1
RewriteRule ^index.html$ index.php [L]

Okay, several changes here. I changed * to +, removed the / before index.php in both rules, and added a $ after html in the first rule. I've tested it on my account and it seems to be working fine.
--Ben
Ben@freepgs.com

Guide

Great, it's working now!
Thanks to all of you :)