.htaccess, localhost working, host not working

Hello everybody.

I have a website on localhost and a configured .htaccess for the local version but its not working online.

for example, this is a bit of code that transfers to message.php on localhost

RewriteRule ^messages/? message.php

on the host, i tried this…

RewriteRule ^www.mywebsite.com/messages/? message.php
Rewriterule ^http://www.mywebsite.com/messages/? message.php (with changing the in php to www.mywebsite.com/message)

How do I create valid links to my php files and how does apache gets his url?
For example, if my url is just ‘poruke’, does apache knows that www.mywebsite.com goes before it?
What kind of string gets into .htaccess file before being redirected with regular expressions?

I know that theres an extensive documentation, but its not on my learning schedual yet. Apache is behind design patterns and javascript
so all the help is welcome in temporary fixes.

Thank you in advance.

That rewrite rule looks mostly fine to me. Might be safer to add an end anchor (^messages/?$) but I don’t think that’s causing your current issue. If this rule works on your local server but breaks on your live server, then I can only suspect that there’s either a different configuration or more stuff in your live htaccess file.

Definitely none of those will work. The scheme and host will never be part of the string that you’re matching against.

Htaccess rewrite rules will match on the relative filesystem path. So if the request is for site.com/poruke, then the relative path that will be matched and replaced will be just “poruke”.

thanks for the answer but the file is copy/pasted from localhost directly to host. I didn’t change anything.
My host provided the .htaccess file form me, an empty one so I presume that it should work.
My rule for the messages is the first rule in the file and followed by the [L] flag so it shouldn’t be that.
I also have a top rule ‘Options +FollowSymLinks’. I doesn’t work with it or without it so i changed a rule
to Options All but that doesn’t work either.

I use xampp. Do you know how can change configuration on the host to reflect that of xampp? I know it might be
a complicated question so i won’t mind if you wont bother with it.

Any chance you can show your whole htaccess file? You never know where the real problem may be.

RewriteEngine On

RewriteRule ^poruka/? poruka.php [L]
RewriteRule ^kontakt/? kontakt.php [L]
RewriteRule ^prijava/? prijava.php [L]
RewriteRule ^registracija/? registracija.php [L]
RewriteRule ^rezervacije/([0-9]+)/? rezervacija.php?id=$1 [L]
RewriteRule ^rezervacije/(delete-[0-9]+)/? rezervacija.php?do=$1 [L]
RewriteRule ^(svakodnevno-cvijece|blagdani-i-praznici|gotovi-aranzmani|posebne-prigode|uredivanje-doma)/? odjeljci.php?odjeljak=$1 [L]
RewriteRule ^Oliva-(.*)/([0-9]+)/?$ proizvod.php?naslov=$1&id=$2 [L]

this is croatian. cause im croat haha. anyway, this is it, nothing changed.
The first rule is to poruka.php a.k.a message.php.

i should also mention that i use a free domain for the site. its 000webhost.com if thats a clue.

i did it. i solved it. i only had to add RewriteBase / to the start of the file. Thanks a lot for your help.