Forum Moderators: phranque

Message Too Old, No Replies

Is my syntax wrong? RewriteRules

RewriteCond RewriteRule mod_rewrite

         

ElectronMan

3:36 am on Nov 17, 2007 (gmt 0)

10+ Year Member



I am not sure why, but my .htaccess file causes a 500 server error. It looks to me like my syntax is correct but I just started learning this stuff yesterday. Can someone please check this for me? It is in the root directory. The first the purpose is to redirect .htm or .html requests to .php request. The second purpose is to redirect requests that look like
[mysite.com...]
into
[mysite.com...]

Here is my .htaccess file:

# .htaccess for root

# godaddy stuff to make php5 default
AddHandler x-httpd-php5 .php
AddHandler x-httpd-php .php4

# turn on mod_rewrite
Options +FollowSymlinks
RewriteEngine on

# set the base to the root
RewriteBase /

# redirect .htm or .html requests into .php
RewriteRule ^(.+)\.htm(.?)$ /$1.php [R=301,NC, L]

# filter page requests through the index
RewriteRule ^/([A-Za-z]*)$ /index.php?page=$1 [R=301, NC, L]

phranque

3:51 am on Nov 17, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], electronman!

if you have a 500 error you also have an entry in the error log with some useful information...

ElectronMan

3:59 am on Nov 17, 2007 (gmt 0)

10+ Year Member



Thanks for the welcome. I am using a shared linux server so I don't think there is any way to check the error log. The two rules are definitely the cause. When I take out both rules, no server error occurs. When I put just one of them server error, doesn't matter which one. Also I updated the 2nd rule, because it was a little bit wrong. Here are my rules now.:

# redirect .htm or .html requests into .php
RewriteRule ^(.+)\.htm(.?)$ /$1.php [R=301,NC, L]

# filter page requests through the index
RewriteRule ^([A-Za-z]*)$ /index.php?page=$1 [NC, L]

jdMorgan

4:52 am on Nov 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Remove the spaces in the flags, e.g. "[R=301, L]" should be "[R=301,L]".
You *may not* format Apache directives freely -- The format is very strict in all cases, and absolutely strict in many.

Many shared hosting plans make the error log available, and it is well-worth digging for it -- or even demanding it. :) Some problems are pretty much impossible to fix without it.

Jim

jdMorgan

4:57 am on Nov 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



By the way, the [NC] (i.e. No Case sensitivity) flag makes it unnecessary to use [A-Za-z], so your second rule can be written as

RewriteRule ^([a-z]*)$ /index.php?page=$1 [NC,L]

Jim

ElectronMan

7:44 am on Nov 17, 2007 (gmt 0)

10+ Year Member



Nice! I took out the two spaces and now its fine. I sent godaddy an email asking them how to get to the error log too. Thank you for your help.

ElectronMan

10:00 pm on Nov 17, 2007 (gmt 0)

10+ Year Member



Just to update on my contact with GoDaddy about being able to see the error log. They said that I have to purchase a more expensive hosting plan to be able to view an error log... So far, I am less than impressed with how GoDaddy supports (or should I say doesn't support) the customers who don't pay for their more expensive services.