Jump to content


Need help with mod rewrite


5 replies to this topic

#1 Extinct

    Young Padawan

  • Members
  • Pip
  • 27 posts
  • Gender:Male
  • Location:USA

Posted 03 February 2007 - 02:06 PM

I got another problem. Can't get mod_rewrite to work. I searched around at first and looked at different tutorials, even tried to do it with those rewrite generators.

My URL is currently like this: home.php?x=matches&page=viewmatches
I want to have it like this matches/viewmatches/ instead
I am currently testing this on my local server. The site is located at http://127.0.0.1/new
So it is not in the root directory ( htdocs ) Does this matter when I use mod_rewrite?

Could someone please guide me on doing this.

This is my code:

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^(.*)/(.*)/$ home.php?x=$1&page=$2 [L]

and the PHP nav:

<?
if (isset($_GET['page']) && isset($_GET['x']) && file_exists('mods/'.$_GET[x].'/'.$_GET[page].'.php')) {
include 'mods/'.$_GET[x].'/'.$_GET[page].'.php';
}
else {
include ("news.php");
}
?>

I tried going to http://127.0.0.1/new...hes/viewmatches it worked... well it came up the page but no images and no css. All messed up.

But anyway that's not how I want it to be.. it should be 127.0.0.1/new/matches/viewmatches

//Extinct - Help appreciated!

#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 03 February 2007 - 04:11 PM

I've not been able to get anything with .htaccess to work with my localhost; but then again, I've not pushed it.

As for the no images and no CSS, in order for them to work with mod_rewrite, they must link to the root. For example, if the image 'images/thing.gif' was to be displayed, you must give it either the direct path, or a preceding slash: '/images/thing.gif'. Same thing for anything else that is linked (by client-side that is), such as JavaScript, styles, even objects and frames. Otherwise, it tries to grab the stuff relative from that page, as the mod_rewrite tricks the browser into thinking it is inside of a large directory. So for example, in your case, it might be trying to load the image '127.0.0.1/new/matches/viewmatches/images/thing.gif' (provided you got the whole rewrite to work).

If you were to upload everything to an online server it would all work just fine. ^_^

#3 Extinct

    Young Padawan

  • Members
  • Pip
  • 27 posts
  • Gender:Male
  • Location:USA

Posted 03 February 2007 - 04:53 PM

Thanks for the reply Demonslay. Could you help me with the RewriteRule code, I wrote that it only works when I go to 127.0.0.1/new/home.php/matches/viewmatches/.

How do I make it 127.0.0.1/new/matches/viewmatches/ Could you help me with the code?
My PHP nav is like this: home.php?x=matches&page=viewmatches

Extinct

#4 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 03 February 2007 - 09:36 PM

There's absolutely nothing wrong with your rewrite rule, its the exact same as I've used thousands of times (only I use the '[nc]' modifier on the end to make it not case-sensitive since I've no clue what the '[L]' modifier does).

You say you were able to get the 127.0.0.1/new/home.php/matches/viewmatches/ to work? I'm wondering how that would be possible, are you sure it's even showing the correct page when you do that? Try changing it and seeing if it will even include other pages, as I highly doubt that it works as you think it does.

I'm going to look into configuring and fine-tuning Apache now that I'm thinking of it and I'm completely bored, lol. If I find anything on this (as it's what I'm assuming since I've never been able to get .htaccess to work with my localhost) I'll drop you a couple links. :angrylooking:

#5 Extinct

    Young Padawan

  • Members
  • Pip
  • 27 posts
  • Gender:Male
  • Location:USA

Posted 04 February 2007 - 05:10 AM

Okey thanks.

One more thing, when I looked at some tutorials which said how I would enable mod_rewrite on my apache server. They said to uncomment #LoadModule rewrite_module modules/mod_rewrite.so, I did that. They also said to uncomment a line called #AddModule mod_rewrite.c and ClearModuleList. But these last 2 lines does not exist in my apache httpd.conf. I am using Apache 2.0.59, is it normal to not have these 2 lines? Or is something wrong

Edited by Extinct, 04 February 2007 - 05:14 AM.


#6 Extinct

    Young Padawan

  • Members
  • Pip
  • 27 posts
  • Gender:Male
  • Location:USA

Posted 04 February 2007 - 11:41 AM

Okey you can close this topic I figured this out myself, if anyone got this problem too i'll tell you how to do it.

All you need to do is change:

AllowOverride None to All in httpd.conf for .htaccess

Just search for this to find the line:
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
	AllowOverride None

Edited by Extinct, 04 February 2007 - 11:42 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users