0

I have just uploaded a site which worked perfectly on one host to another and the .htaccess file with the rewrite rule doesn't work.

On the live location, the .htaccess file has this in it:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([A-Za-z\-0-9]+)$ index.php?page=$1 [QSA]
ErrorDocument 404 /index.php

This should rewrite the URLs from

www.mysite.co.uk/?page=about

To:

www.mysite.co.uk/about

When I try it on the new host it throws an error in the browser:

Internal Server Error, this is an error with your script, check your error log for more information.

When I check the error log it says:

[Fri May 30 10:51:53 2014] [alert] [client 87.127.116.49] /domains/m/i/mysite.co.uk/public_html/.htaccess: RewriteRule: cannot compile regular expression '^([A-Za-z\\-0-9]+)$'\n

Can anyone help?

hakre
  • 193,403
  • 52
  • 435
  • 836
Pete Naylor
  • 776
  • 2
  • 14
  • 33
  • 1
    you are probably using a different apache version check if versions are the same – Freelancer May 30 '14 at 10:10
  • try `^([\w\-]+)$`. Maybe this behavior depends on the hyphen position. – Deadooshka May 31 '14 at 14:54
  • If you ask a question about an error message you don't understand, please make it specific what you don't understand with that error message. Otherwise such questions tend to not getting any good answers. If the problem persists, please edit your question to make this more clear. If you have solved it, please outline shortly in a comment what the issue was so I can flag the question for re-opening and you can answer your own question then. - As the duplicate question suggests, you should outline as well in your question which server version you were using on localhost and on the remote server. – hakre Oct 09 '14 at 12:26

1 Answers1

0

I think that you've confused yourself a bit?

Why would you want to write www.mysite.co.uk/?page=about to www.mysite.co.uk/about

What about this:

When a vistior reaches:

www.mysite.co.uk/about

What they are actually seeing is:

www.mysite.co.uk/?page=about

But the client URL is still:

www.mysite.co.uk/about

And this is still an alternate and unfriendly url:

www.mysite.co.uk/?page=about

You need this:

    RewriteEngine on
    RewriteRule ^(.*)$ index.php?page=$1

And note that you would need to have index.php contain something like:

<?php
if (isset($_GET['page']))
{
    $pageToDisplay = $_GET['page'];
    # I would test at this point, so:
    echo 'I am over here, I got this info: '.$_GET['page'].''; exit;
    // Display the appropriate page
}
else
{
    # I would test at this point, so:
    echo 'I got here empty handed...'; exit;
    // Display your homepage
}
?>

If you are getting a 500 after this, I would made sure that all modules are enabled. It seems like you're running an older version of Apache and I would make sure that what you are trying to do has full support within the Apache rewrite module for that version?

Also see here: Pretty URLs with .htaccess Rewriting Tips.

The author details Twitter like friendly URLs.

Craig van Tonder
  • 7,497
  • 18
  • 64
  • 109
  • Thanks for your reply, I have tried that but I still get the error: Internal Server Error, this is an error with your script, check your error log for more information. My Apache version is: Apache/1.3.41 (Unix) mod_ssl/2.8.31 OpenSSL/0.9.7e-p1 – Pete Naylor May 30 '14 at 13:24
  • Is the rewrite module enabled in Apache? I see that you have enabled FollowSymLinks, you would indeed need that for rewrite to work... What does the error log say? – Craig van Tonder May 31 '14 at 13:47