Web Hosting Forum | Lunarpages
News: October 6, 2008 - Submit Your Site for the October 2008 Site of the Month!
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 06, 2008, 07:40:39 AM


Login with username, password and session length


Pages: [1]   Go Down
  Print  
Author Topic: What's wrong with this .htaccess ?  (Read 155 times)
renefournier
Newbie
*
Offline Offline

Posts: 4


WWW
« on: July 24, 2008, 08:20:59 AM »

AddHandler application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_METHOD} ^trace$ [NC]
RewriteRule .* - [F,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^((en|de|ru)/[a-z0-9-_]+)\.php$ /$1/ [NC,R=301,L]
RewriteRule ^((en|de|ru)/[a-z0-9-_]+)$ /$1/ [NC,R=301,L]
RewriteRule ^(en|de|ru)/([a-z0-9-_]+)/$ /index.php?lang=$1&page=$2 [NC,QSA,L]

-----

Apache 1.3.39, throwing a 500 Internal Server Error.

Logged
Mitch
Lunarpages Traffic Cop
Senior Moderator
Berserker Poster
*****
Online Online

Posts: 7896



WWW
« Reply #1 on: July 24, 2008, 08:25:13 AM »

Could you please explain more about what you are trying to do and I am sure somebody here will be more than happy to take a look.
Logged

renefournier
Newbie
*
Offline Offline

Posts: 4


WWW
« Reply #2 on: July 24, 2008, 08:33:52 AM »

I have a subdomain ( http://czechpoint101.renefournier.com/ ) where I need the URLs rewritten, e.g.:

http://czechpoint101.renefournier.com/en/home/
http://czechpoint101.renefournier.com/index.php?lang=en&page=home

I'm using the above same .htaccess on my MacBook Pro (Apache 2, mind you), and it works fine. The only thing I can think of is that the subdomain is not in the real doc root (although as a virtual host it should appear that way to Apache, no?).

Here's the exact .htaccess I'm using locally, and does what I need:

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_METHOD} ^trace$ [NC]
RewriteRule .* - [F]

# Remove .php if it's not a real file.
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^((en|de|ru)/[a-z0-9-_]+)\.php$ /$1/ [NC,R=301,L]

# Force the trailing slash.
RewriteRule ^((en|de|ru)/[a-z0-9-_]+)$ /$1/ [NC,R=301,L]

RewriteRule ^(en|de|ru)/([a-z0-9-_]+)/$ /index.php?lang=$1&page=$2 [NC,QSA,L]

Logged
PixiWork
Graphic/Web Dev Designer
Intergalactic Cowboy
*****
Offline Offline

Posts: 50



WWW
« Reply #3 on: July 25, 2008, 09:53:09 PM »

Have a look at this page, I got this one working.

http://spindrop.us/2006/07/26/how-to-remove-file-extensions-from-urls/

I had the same issue like you before that it isn't working properly.
Logged

MrPhil
Quantum Encyclopedia Writer
*****
Offline Offline

Posts: 3381



« Reply #4 on: July 26, 2008, 07:50:28 PM »

Where is this .htaccess file located? If it's in the primary root (public_html/.htaccess), don't forget that your subdomain's name will usually be renefournier.com/czechpoint101/ and not czechpoint101.renefournier.com. I don't know if the name will be "canonical" by the time it gets to public_html/czechpoint101/.htaccess. Anyway, if that's what's happening, your RewriteRule patterns won't match because there's a "czechpoint101/" in front.

I'm not sure if Apache 1.3.3.9 will correctly handle nested parentheses ((pattern)more pattern), or if that's only Apache 2. I believe you can request to be moved to a server with Apache 2, if that's vital. An alternative would be to make an individual pattern for each language.

Finally, don't forget to clear your browser cache after any change to .htaccess.
Logged

renefournier
Newbie
*
Offline Offline

Posts: 4


WWW
« Reply #5 on: July 27, 2008, 02:34:04 AM »

Thanks for the replies. I too thought maybe the parenthesis issue was to blame, and so I focused on it for a while... Turns out, it was something else. Notice the difference:

BEFORE (doesn't work):

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^trace$ [NC]
RewriteRule .* - [F]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^((en|de|ru)/[a-z0-9-_]+)\.php$ /$1/ [NC,R=301,L]
RewriteRule ^((en|de|ru)/[a-z0-9-_]+)$ /$1/ [NC,R=301,L]
RewriteRule ^(en|de|ru)/([a-z0-9-_]+)/$ /index.php?lang=$1&page=$2 [NC,QSA,L]

AFTER (works! -- http://czechpoint101.renefournier.com/en/home/ ):

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^trace$ [NC]
RewriteRule .* - [F]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^((en|de|ru)/[a-z0-9_-]+)\.php$ /$1/ [NC,R=301,L]
RewriteRule ^((en|de|ru)/[a-z0-9_-]+)$ /$1/ [NC,R=301,L]
RewriteRule ^(en|de|ru)/([a-z0-9_-]+)/$ /index.php?lang=$1&page=$2 [NC,QSA,L]

Yup, the only thing I changed was the order of the underscore and hyphen in the last two rules. Can anyone tell me why this fixes the problem? The Apache 1.3 docs are incredibly verbose, and I couldn't find a specific reference on this type of thing, although my suspicion is that having the hyphen and then the underscore maybe makes mod_rewrite treat it as a range instead of a character?

...Rene
Logged
MrPhil
Quantum Encyclopedia Writer
*****
Offline Offline

Posts: 3381



« Reply #6 on: July 27, 2008, 07:39:44 PM »

You'd think that 0-9-_ wouldn't be taken as a range-range, but stranger things have happened. Evidently the regular expression parser is fairly simple-minded and your original construct must have messed up its mind. Anyway, always put a lone hyphen (literal character to be matched) at the very end of the list. Good to hear you finally got it working.
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.6 | SMF © 2006-2008, Simple Machines LLC

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM