Author Topic: [SOLVED] Rewrite engine  (Read 673 times)

Offline Jesterhead

  • Level 8
  • *
  • Posts: 41
  • Reputation: +1/-0
  • In Flames we trust!
    • View Profile
[SOLVED] Rewrite engine
« on: November 28, 2010, 07:23:29 AM »
Hello everyone,

It's me again with a silly question.

As codestryke told me in my previous topic, you can rewrite your url's trough the htaccess file.
I tried it and.. success!

Code: [Select]
RewriteEngine On
RewriteRule ^([A-Za-z0-9]+)$ index.php?page=$1

So I also wanted to use this for nice profile and activate links.

Code: [Select]
RewriteEngine On
RewriteRule ^([A-Za-z0-9]+)$ index.php?page=$1
RewriteRule ^profile/([A-Za-z0-9]+)$ index.php?page=profile&id=$1
RewriteRule ^activate/([A-Za-z0-9]+)$ index.php?page=activate&id=$1

This works, the code is excecuted. Altough.. all my css styles are ignored (and it looks like a 3 year old kid made it).
I tried bascially everything i could think of. Any idea's?

Thank you!
« Last Edit: November 28, 2010, 01:21:07 PM by Jesterhead »

Offline Marek

  • Level 18
  • *
  • Posts: 177
  • Reputation: +7/-0
  • XHTML, CSS, JS, PHP and MySQL are my pantheon.
    • View Profile
Re: Rewrite engine
« Reply #1 on: November 28, 2010, 11:09:08 AM »
This is a side effect of rewriting urls, because of relative links. When a link is relative (when it doesn't begin with a slash) the browser will try to resolve it relative to the page being viewed. Since you introducted url rewriting, the browser is looked at a url like "/profile/blah" so it's looking for your css relative to the (non-existent) /profile/ directory.

The solution is to change your all relative your links absolute links (with an initial slash). This way the browser will always load /style.css (at the root) regardless of the URL.

Offline Jesterhead

  • Level 8
  • *
  • Posts: 41
  • Reputation: +1/-0
  • In Flames we trust!
    • View Profile
Re: Rewrite engine
« Reply #2 on: November 28, 2010, 12:59:56 PM »
Thank you for your resonse,

So in fact I have to change every link in all my files to fix this? such as:
Code: [Select]
<?php include('navigation.php'); ?> to <?php include('/navigation.php'); ?>
<img src="images/avatar.png"> to <img src="/images/avatar.png">
<a href='home'> to <a href='/home'>
<form action='register'> to <form action='/register'>

Or only a specific one?

Offline Nox

  • Level 35
  • **
  • Posts: 767
  • Reputation: +12/-2
    • View Profile
Re: Rewrite engine
« Reply #3 on: November 28, 2010, 01:15:31 PM »
nano meant in CSS... dunno how to do dynamically except using find&replace or LessCSS(LessPHP) etc.

the code would most likely not work 'cause include not prefixed by http: does not use http but filesystem request and / would point to root folder of the drive, while root might be something like
Code: [Select]
/hosting/www/<yourdomain>/<yoursubdomain>/
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline Jesterhead

  • Level 8
  • *
  • Posts: 41
  • Reputation: +1/-0
  • In Flames we trust!
    • View Profile
Re: Rewrite engine
« Reply #4 on: November 28, 2010, 01:20:44 PM »
Thank you!
I'm glad it's only changing 1 link. This fixed it:

Code: [Select]
<link href="http://www.mydomain.be/folder/stylesheets/style.css" rel="stylesheet" type="text/css" media="screen" />
I like these forums :)

Offline Nox

  • Level 35
  • **
  • Posts: 767
  • Reputation: +12/-2
    • View Profile
Re: [SOLVED] Rewrite engine
« Reply #5 on: November 28, 2010, 01:24:33 PM »
Well... probably not as long as you would use background images... then you'll have to maintain the links inside CSS too
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal