0

I'm useing this code:

RewriteEngine on
RewriteRule ^(.*)/exampelFile exampelFile.php?data=$1 [L]

and my problem is that the page dosn't load my css&js file. It seems the php page it self is getting loaded form

www.example.com/some text/exampelFile...

insted of

www.example.com/exampelFile?data=some text...

and this why it dosn't find the css&js files

1 Answers1

0

This is because your rewrite rule only does internal rewriting and doesn't redirect the browser to that URL. Therefore the browser is still on page www.example.com/some_text/exampelFile; all the relative links and locations in the HTML of your exampelFile.php are relative to that location, not to the actual file location, as they are obtained by the browser.

You could prevent this by making it a redirect with RewriteRule's flag R:

'redirect|R [=code]' (force redirect)

Prefix Substitution with http://thishost[:thisport]/ (which makes the new URL a URI) to force a external redirection. If no code is given, a HTTP response of 302 (MOVED TEMPORARILY) will be returned.

Resulting:

RewriteEngine on
RewriteRule ^(.*)/exampelFile /exampelFile.php?data=$1 [L,R=301]
Esa Jokinen
  • 49,773
  • after putting this flag it send me to 404 Error – user5460170 Jun 06 '17 at 06:10
  • On what location? Before or after the redirection? Is there something on that location? – Esa Jokinen Jun 06 '17 at 06:14
  • when I redirect with R flag, so it send me to he actual link http://example.com/exampelFile?data=some_text but I want it to overide the URL, so the presented URL in the URL toolbar http://example.com/some text/exampelFile (thats the hol point in useing htaccess so the pressented link will be more elegant.. – user5460170 Jun 06 '17 at 12:00
  • If you change the directive to an external redirect (ie. R=3xx) then you'll need to make the substitution root-relative or absolute, otherwise the directory-prefix will be added back (in .htaccess) and break the redirect. Unless of course the RewriteBase has already been set, then you don't need to. – MrWhite Jun 07 '17 at 14:57