Rewrite Rules 1and1 Internet

Hi there, I was wondering if someone could help, I am on one and one internet and i have trouble with Rewriterules. I have solved almost all of them by lookin online but i have just a couple of errors to solve.

On my site a couple of links to other pages do not work they are, Write a review, Terms and conditions and Privacy Policy, the links are on this page
http://holiday-rentals-villas-cottages.co.uk/1002

1and1 are blaming my designer and my designer is blaming them. Up until now it has all been 1and1 internets fault. my .htaccess file go’s like this,

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
AddType x-mapp-php5 .php
RewriteRule ^([a-zA-Z0-9_-]+)$ view.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ view.php?id=$1
RewriteRule ^review/([a-zA-Z0-9_-]+)/$ review.php?id=$1
RewriteRule ^review/([a-zA-Z0-9_-]+)/$ review.php?id=$1
RewriteRule ^pages/([a-zA-Z0-9_-]+)$ pages.php?page=$1
RewriteRule ^pages/([a-zA-Z0-9_-]+)/$ pages.php?page=$1
RewriteRule ^contactus\.html$ /contactus\.php$1
RewriteRule ^index\.html$ /index\.php$1
RewriteRule ^googlemap\.html$ /googlemap\.php$1

Thanks in advance if anyone can help

  1. You’re not using Alias or AliasMatch, so you don’t need RewriteBase / – drop it

  2. It looks like properties are always identified by numbers, like domain/1001, domain/1002, domain/review/1001, domain/review/1002. Is this always true? If so, change all the occurences of ([a-zA-Z0-9_-]+) to ([0-9]+). There’s no sense to go looking for alpha characters if you’re sure there’ll never be one.

  3. Put [L] after all your rules to prevent Apache from burning CPU cycles for nothing

  4. Some rules look pretty redundant, for example


RewriteRule ^([a-zA-Z0-9_-]+)$ view.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ view.php?id=$1

Those are basically the same rule, except for the / at the end. You can combine them into one rule:


RewriteRule ^([a-zA-Z0-9_-]+)[COLOR="Red"]/?[/COLOR]$ view.php?id=$1

But it would be even better to just pick one of:

  1. Always end URLs in a trailing slash
  2. Never end URLs in a trailing slash

And then stick to it, instead of allowing both, which is a bit poor practice IMHO.

  1. The Terms & Conditions and Privacy policy pages also don’t work when you provide the internal URLs (http://holiday-rentals-villas-cottages.co.uk/pages.php?id=terms and http://holiday-rentals-villas-cottages.co.uk/pages.php?id=policy respectively)

  2. The following works for me:


Options +SymLinks
AddType x-mapp-php5 .php

RewriteEngine On
RewriteRule ^([0-9_-]+)/?$ view.php?id=$1 [L]
RewriteRule ^review/([0-9]+)/?$ review.php?id=$1 [L]
RewriteRule ^pages/([0-9]+)/?$ pages.php?page=$1 [L]
RewriteRule ^contactus\\.html$ contactus\\.php [L]
RewriteRule ^index\\.html$ index\\.php [L]
RewriteRule ^googlemap\\.html$ googlemap\\.php [L]

Actually, some hosts do demand that you use RewriteBase (I was with one once, a free host). I wrote a script once that used mod_rewrite and someone who was with 1and1 told me some problems they had were due to not having RewriteBase in there, so it may be necessary for you.

I tried the above and no success so i put the .htaccess file back as it was as i was getting even more errors. I forgot to mention, I know nothing about rewriterules or any programming, I have been looking on forums for solutions, from what i have seen, 1and1 internet seem to have a lot of issues with rewrite rules.

I just received an email from 1and1 saying,

The reason why it shows error 404 because the subdirectory pages does not exist in Znprs directory where your domain name is currently pointed. Please double check your files.

This problem was worse when i started but slowly getting better, does anyone else have any ideas???
Without the RewriteBase / it does not work so it must be needed with 1and1

Thanks for any input, Steve.

Well, have you double checked your files, or let the designer double check the files, like 1&1 suggested?

My designer said they are fine but how would i tell?

It must be 1and1 because I cant use my wordpress theme without adding the line, AddType x-mapp-php5 .php

The designer said the script was designed to work with PHP5 and above, 1and1 has 4.9.

Also I added some forward slash and backslashes to the rewrite rules which i found on another forum, this helped me to view more pages as at the begining I could only see a few pages. The site is almost fully operational apart from these 3 problems.

And the code I showed in post #6 doesn’t work, if you add RewriteBase / of course ?


Options +SymLinks
AddType x-mapp-php5 .php

RewriteEngine On
RewriteBase /
RewriteRule ^([0-9_-]+)/?$ view.php?id=$1 [L]
RewriteRule ^review/([0-9]+)/?$ review.php?id=$1 [L]
RewriteRule ^pages/([0-9]+)/?$ pages.php?page=$1 [L]
RewriteRule ^contactus\\.html$ contactus\\.php [L]
RewriteRule ^index\\.html$ index\\.php [L]
RewriteRule ^googlemap\\.html$ googlemap\\.php [L]

if not, can you tell me what’s going wrong?

It does not work i get this error,

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webadmin@kundenserver.de and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

Thanks for any help, Steven.

Very weird. It works fine on my local system here.

Could you remove line by line and test if it works in between each time? i.e. remove the last line, load the website to see if it works, if not remove the line before the last line, load the website, etc, etc.

That will show which line is causing the error.

I did just spot some extraneous backslashes. It won’t solve the problem, but it will look better cleaner:


Options +SymLinks
AddType x-mapp-php5 .php

RewriteEngine On
RewriteBase /
RewriteRule ^([0-9_-]+)/?$ view.php?id=$1 [L]
RewriteRule ^review/([0-9]+)/?$ review.php?id=$1 [L]
RewriteRule ^pages/([0-9]+)/?$ pages.php?page=$1 [L]
RewriteRule ^contactus\\.html$ contactus.php [L]
RewriteRule ^index\\.html$ index.php [L]
RewriteRule ^googlemap\\.html$ googlemap.php [L]

Does not work, just get error message,

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webadmin@kundenserver.de and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

And what happened when you removed line by line?

I pasted the whole lot in and got the server error, I did not try line by line. I put the extra slashes on as I see a post about 1and1 trouble on another site and it got more of the site working. gonna try your recommendation now.

This is how it now looks and is working with streamlined version,

Options +FollowSymlinks
AddType x-mapp-php5 .php
RewriteEngine on
RewriteBase /
RewriteRule ^index\.html$ index.php [L]
RewriteRule ^([0-9_-]+)/?$ view.php?id=$1 [L]
RewriteRule ^review/([0-9]+)/?$ review.php?id=$1 [L]
RewriteRule ^pages/([0-9]+)/?$ pages.php?page=$1 [L]
RewriteRule ^contactus\.html$ contactus.php [L]
RewriteRule ^googlemap\.html$ googlemap.php [L]

This links in the footer dont work - Terms and Conditions - getting 404
This links in the footer dont work - Privacy Policy - getting 404

And on a property page - write a review dont work. getting 404

Yesterday I Contacted 1an1 about these issues this is what they said,

Thank you for contacting us.

The reason why it shows error 404 because the subdirectory pages does not exist in Znprs directory where your domain name is currently pointed. Please double check your files.

Would you know how to find this out,

thanks again.

For the pages you do need to accept alpha characters. My last idea to is move the first rewriterule last. While it shouldn’t be needed, it is a bit more clear.


Options +FollowSymlinks
AddType x-mapp-php5 .php

RewriteEngine On
RewriteBase /
RewriteRule ^index\\.html$ index.php [L]
RewriteRule ^contactus\\.html$ contactus.php [L]
RewriteRule ^googlemap\\.html$ googlemap.php [L]
RewriteRule ^review/([0-9]+)/?$ review.php?id=$1 [L]
RewriteRule ^pages/([a-zA-Z0-9_-]+)/?$ pages.php?page=$1 [L]
RewriteRule ^([0-9]+)/?$ view.php?id=$1 [L]

If that doesn’t work, I’m out of ideas. This code is a clean as it gets; if it doesn’t work something else must be wrong.

Thanks for all your help, I will contact them tomorrow, I have noticed some of the php has been encrypted, I found a decrypter online over the weekend but could not get it to work, as i cant see the files they could be corrupted, Thanks again, regards steven.

Does it matter which order the rewrite rules are apart from the first 4?

With these particular rules, no. They are mutually exclusive (if one matches all the others don’t).

Hi there, do you know anything about mod_rewrite, my website has been tested and they are saying it is not enabled for apache http://holiday-rentals-villas-cottages.co.uk/rewrite.php

I assume you did put the rules you need in the .htaccess?

besides, if it really didn’t work, URLs with just the numbers wouldn’t work either.
So it does work. Something else is wrong.

Hi there, me again, i was wondering if i could pick your brains?

I moved the site to another webhost provider now the site is working, i even used the modified htaccess file you provided. Is there a way of speeding up the site through the htaccess file or removing whitespace from the html,

thanks in advance, regards Steven.

PS if you have any plumbing/property maintenance issues I can help you with them.