Forum Moderators: phranque

Message Too Old, No Replies

500 Error with .htaccess

         

Rightz

4:56 pm on Sep 15, 2007 (gmt 0)

10+ Year Member



I was trying to alter the .htaccess so I can use php includes and to redirect mysite.co.uk to www.mysite.co.uk

I copied the entire code I use from one site, changed the web address and put it on my new site.

I isn't working though on the new site.

What am I doing wrong?

AddType text/html .shtml .html

AddHandler server-parsed .shtml .html

RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.example.co.uk/ [R=301,L]

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.co.uk [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [L,R=301]

AddHandler server-parsed .html
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

[edited by: jdMorgan at 2:10 pm (utc) on Sep. 16, 2007]
[edit reason] example.co.uk [/edit]

Dilly

5:17 pm on Sep 15, 2007 (gmt 0)

10+ Year Member



I am a complete newbie at this but I had the same problem when I started with modrewrite this morning. I removed this line from my .htaccess and the 500 error was gone.

Options +FollowSymLinks

No idea if it will work for you but it's worth a try.

jdMorgan

5:30 pm on Sep 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Rightz,

You've got two copies of "RewriteEngine on" in there, and the Options statement should go at the top of the rewrite code -- If you need it, and if it's allowed.

Basically, you must have Options +FollowSymLinks or Options +SymLinksIfOwnerMatch set in either your server configuration file or in your .htaccess file. Otherwise, you cannot use mod_rewrite.

However, some hosts will set one of those options for you, but not allow you to change it. So as Dilly observes, you can indeed get an error if you try to change Options but are not allowed by your host to do so.

The mod_rewrite part of your code should look like this:


Options +FollowSymLinks
RewriteEngine on

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.example.co.uk/ [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.co\.uk [NC]
RewriteRule (.*) http://www.example.co.uk/$1 [L,R=301]

and as stated, you might not need or might not be allowed to use the Options directive. There's no way to tell, so you have to test. If you do get an error, then check your raw server error log file -- It will often tell you exactly what is wrong.

Jim

[edited by: jdMorgan at 5:31 pm (utc) on Sep. 15, 2007]

g1smd

2:00 pm on Sep 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You also have two AddHandler statements and one RemoveHandler statement.

Those should be rationalised.

Rightz

5:44 pm on Sep 17, 2007 (gmt 0)

10+ Year Member



Ok I've tried to just put the following in and it isn't working.


Options +FollowSymLinks
RewriteEngine on

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.example.co.uk/ [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.co\.uk [NC]
RewriteRule (.*) http://www.example.co.uk/$1 [L,R=301]

I've got various sites with this host and use Options with all the other sites so cant think why the above shouldn't work.

Any clues?

Thanks for your suggestions so far.

g1smd

8:12 pm on Sep 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Which bit doesn't work? How doesn't it work?

The index redirect can only support index files in root, not in folders.

Rightz

11:02 am on Sep 19, 2007 (gmt 0)

10+ Year Member



Ok the redirect from non-www to www is working.

Now I just need to work out how to allow php includes!

[edited by: Rightz at 11:14 am (utc) on Sep. 19, 2007]

g1smd

11:24 am on Sep 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Look at the AddType directive if you need to retain .html filenames but have PHP scripts insode them.

Rightz

11:29 am on Sep 19, 2007 (gmt 0)

10+ Year Member



Thank you!

Out of curiousity what are peoples suggestion for keeping .html or having .php pages. I always prefered the look of .html but maybe I am wrong?

g1smd

11:40 am on Sep 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Keep the same URLs when you change technology. A new URL is a new page. You lose all the "age" benefit that the old page had accrued.

I know of a site that uses PHP scripting, but all the URLs end in .asp as the site used to run on ASP scripts some years ago.

Rightz

12:09 pm on Sep 19, 2007 (gmt 0)

10+ Year Member



does it matter if it is a brand new site though?

jdMorgan

12:58 pm on Sep 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Brand new site, or brand-new domain?

The point is to avoid changing URLs, because it is URLs, not pages and not sites, that have PageRank. If you change the URLs, you throw away lots of inbound links, bookmarks, and loyal visitors who type your URLs from memory... While 301 redirects can recover some of this 'accrued value,' it often takes a long time.

Jim