I'm following a book tutorial (Effortless Ecommerce by Larry Ullman) to build an ecommerce site. When I add the following code to my htaccess file to rewrite URLs and also enforce SSL, it returns a 500 error when I try to load my site.
Does anyone have any ideas what the problem/solution might be?
RewriteEngine on
# For sales:
RewriteRule ^shop/sales/?$ sales.php
# For the primary categories:
RewriteRule ^shop/([A-Za-z\ ] )/?$ shop.php?type=$1
# For specific products:
RewriteRule ^browse/([A-Za-z\ \-] )/([A-Za-z\ \-] )/([0-9] )$ browse.php?type=$1&category=$2&id=$3
# For HTTPS pages:
RewriteCond %{HTTPS} off
RewriteRule ^(checkout\.php|billing\.php|final\.php|admin/(.*))$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} off RewriteRule ^(checkout\.php|billing\.php|final\.php|admin/(.*))$ http开发者_StackOverflow中文版s://%{HTTP_HOST}/$1 [R=301,L]
There are some minor syntax errors in your .htaccess. I have fixed them, pls try this:
Options +FollowSymlinks -MultiViews
RewriteEngine on
# For sales:
RewriteRule ^shop/sales/?$ sales.php [L,NC]
# For the primary categories:
RewriteRule ^shop/([^/]*)/?$ shop.php?type=$1 [L,NC]
# For specific products:
RewriteRule ^browse/([^/]*)/([^/]*)/([0-9])/?$ browse.php?type=$1&category=$2&id=$3 [L,NC]
# For HTTPS pages:
RewriteCond %{HTTPS} off
RewriteRule ^(checkout\.php|billing\.php|final\.php|admin/(.*))$ https://%{HTTP_HOST}/$1 [R=301,L,NC]
Is Mod_Rewrite enabled in your Apache configuration? Some providers do not activate it on shared hosts.
I think the problem was what @sparky672 suggested in the comments, namely that I was copying and pasting and maybe invisible characters snuck in
I got this to work now
<IfModule mod_rewrite.c>
RewriteEngine on
# For sales:
RewriteRule ^shop/sales/?$ sales.php
# For the primary categories:
RewriteRule ^shop/([A-Za-z\+]+)/?$ shop.php?type=$1
# For specific products:
RewriteRule ^browse/([A-Za-z\+\-]+)/([A-Za-z\+\-]+)/([0-9]+)$ browse.php?type=$1&category=$2&id=$3
# For HTTPS pages:
RewriteCond %{HTTPS} off
RewriteRule ^(checkout\.php|billing\.php|final\.php|admin/(.*))$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
Where are you copying & pasting it from?
If you're pulling it off a web page, then you're introducing all kinds of invisible characters. If you're using MS Word, you're also introducing extraneous invisibles.
Try using a good text editor, check for invisible junk and copy/paste from there. Or just type it all out long-hand into your control panel editor.
Personally, I use a good text editor and upload via FTP (making sure it's in ASCII text mode).
精彩评论