Jump to content


im trying to get mod_rewrite to work w/my nav


15 replies to this topic

#1 zetsumei

    Young Padawan

  • Publishing Betazoids
  • Pip
  • 269 posts
  • Gender:Male
  • Location:127.0.0.1

Posted 14 August 2006 - 04:20 PM

im trying to use mod_rewrite on my ?id=blah&page=blah urls and i cant seem to get them to work...heres the code im using in my .htaccess

RewriteEngine On
RewriteRule ^site/(.*)\.axsu$ index.php?id=site&page=$1

if you could tell me what i'm doing wrong itd be helpful...

btw, ive looked at every tutorial on this site and still couldnt figure it out :D...

#2 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 14 August 2006 - 04:34 PM

hm...looks fine to me, apart from maybe the uppercase O on On,although im sure this wouldn't make a difference.

How do you mean it does work? Do you get a 404 error? and where are you testing this, localhost or online?

Edited by .Matt, 14 August 2006 - 04:34 PM.


#3 zetsumei

    Young Padawan

  • Publishing Betazoids
  • Pip
  • 269 posts
  • Gender:Male
  • Location:127.0.0.1

Posted 14 August 2006 - 04:40 PM

this is online (not localhost) and am i suppose to change my links from index.php?id=blah&page=blah to /blah/blah or does the .htaccess do that automatically...

#4 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 14 August 2006 - 04:43 PM

You will have to change you links yourself unfortunately. You may wish to do what i have done of late and create an option where you can turn "friendly urls" off in case you move to a server where mod_rewrite is disabled :D

So what's the actual problem you need help with?

#5 zetsumei

    Young Padawan

  • Publishing Betazoids
  • Pip
  • 269 posts
  • Gender:Male
  • Location:127.0.0.1

Posted 14 August 2006 - 04:52 PM

i changed my links from ?id=axsu&page=about to /blah/blah and i get a 404 error not found...

heres my .htaccess code
RewriteEngine On
RewriteRule ^axsu/(.*)\.axsu$ index.php?id=axsu&page=$1

i hope you get what im asking...cause im not good at explaining things...

EDIT: i got it working now, but the pages open up w/o any css styleing...how would i fix this...

example of how it looks w/o mod rewrite: http://axsustudios.c...axsu&page=about

example w/mod rewrite: http://axsustudios.c...bout/about.axsu

Edited by zetsumei, 14 August 2006 - 04:55 PM.


#6 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 14 August 2006 - 04:58 PM

Thats because when you use mod_rewrite you are changing the directory (or so the browser thinks) so to call you style sheet use this instead:

 <link rel="stylesheet" href="/style.css" type="text/css" />

The / should make sure it calls the sheet from the base dir always.

#7 zetsumei

    Young Padawan

  • Publishing Betazoids
  • Pip
  • 269 posts
  • Gender:Male
  • Location:127.0.0.1

Posted 14 August 2006 - 05:01 PM

sorry to keep bothering you...but i put the "/" infront of style.css and it works, but now my pages always display my news except when i enter ?id=axsu&page=about it works fine...

#8 Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 716 posts
  • Gender:Male
  • Location:Texas

Posted 14 August 2006 - 06:24 PM

View Post.Matt, on Aug 14 2006, 09:58 PM, said:

Thats because when you use mod_rewrite you are changing the directory (or so the browser thinks) so to call you style sheet use this instead:

 <link rel="stylesheet" href="/style.css" type="text/css" />

The / should make sure it calls the sheet from the base dir always.


View Postzetsumei, on Aug 14 2006, 10:00 PM, said:

sorry to keep bothering you...but i put the "/" infront of style.css and it works, but now my pages always display my news except when i enter ?id=axsu&page=about it works fine...


I would do like Matt did, but to add to that...

<?php
$url="http://".$_SERVER['HTTP_HOST'];
?>
<link rel="stylesheet" href="<? echo $url; ?>/style.css" type="text/css" />
assuming that is where your style sheet file is, it puts a direct link on it, but it's not really direct because it will change if you move it to a different server/domain name.

#9 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 14 August 2006 - 06:28 PM

SpatialVisionary.....just adding "/" does the exact same thing.....

Anyway....zetsumei, the rewrite seems to be working fine so it may be your actual code, could you post it?

#10 zetsumei

    Young Padawan

  • Publishing Betazoids
  • Pip
  • 269 posts
  • Gender:Male
  • Location:127.0.0.1

Posted 14 August 2006 - 06:36 PM

my links show up as http://axsustudios.c...ct/contact.axsu no matter what i put for my links heres my code...

<html>
<head>
 <title>Axsu Studios v1.0</title>
 <link rel="stylesheet" href="/style.css" type="text/css" />
 <link rel="shortcut icon" href="/images/favicon.ico" />
</head>
<body>
<center>
	<div id="container">
		<div id="head"></div>
		<div id="nav">
				<a href="?id=axsu&page=">Home</a> <a href="?id=axsu&page=about">About</a> <a href="?id=axsu&page=contact">Contact</a>
				<a href="?id=axsu&page=port">Portfolio</a> <a href="?id=tutorials&page=viewtut">Tutorials</a>
				<a href="http://www.tutorialstream.com"><img src="/images/tstream.gif" align="right" width="88px" height="31px" border="0" alt="Tutorial Stream" /></a>
		</div>


#11 Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 716 posts
  • Gender:Male
  • Location:Texas

Posted 14 August 2006 - 06:37 PM

View Post.Matt, on Aug 14 2006, 11:28 PM, said:

SpatialVisionary.....just adding "/" does the exact same thing.....

Anyway....zetsumei, the rewrite seems to be working fine so it may be your actual code, could you post it?

yeah, I guess it's just a preference then. :)

#12 zetsumei

    Young Padawan

  • Publishing Betazoids
  • Pip
  • 269 posts
  • Gender:Male
  • Location:127.0.0.1

Posted 14 August 2006 - 06:42 PM

i get the rewrite to work but it just keeps reshowing my news instead of the actual page content and when i go to click on another link it just adds to the url like this
http://axsustudios.com/axsu/about/axsu/contact/etc....

heres my .htaccess code
AddType application/x-httpd-php axsu
RewriteEngine On
RewriteRule ^axsu/(.*)/(.*)\.axsu$ index.php?id=$id&page=


#13 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 14 August 2006 - 06:46 PM

You will have to adjust your links to when you click another linkit does not add it onto the url. Like this:

<a href="/xxx/yyy/">link name</a>[code]

notice the forward slash at the beginning of the link.

[code]AddType application/x-httpd-php axsu
RewriteEngine On
RewriteRule ^axsu/(.*)/(.*)\.axsu$ index.php?id=$id&page=

That doesnt look right, canyou post your php code please, im sure the page variable should not be left blank. Also you first line in that .htacces file is pointless as your are telling it to parse php through a .axsu file.However when you use mod_rewrite you are not creating a file, its simple a mask.

Edited by .Matt, 14 August 2006 - 06:46 PM.


#14 zetsumei

    Young Padawan

  • Publishing Betazoids
  • Pip
  • 269 posts
  • Gender:Male
  • Location:127.0.0.1

Posted 14 August 2006 - 06:55 PM

ok...i got the links like this: /axsu/page name/page.axsu but the pages never display the right content it always acts as if theres no page and includes the news...

heres my links code
		<div id="nav">
				<a href="/">Home</a> <a href="/axsu/about/about.axsu">About</a> <a href="/axsu/contact/contact.axsu">Contact</a>
				<a href="/axsu/port/port.axsu">Portfolio</a> <a href="?id=tutorials&page=viewtut">Tutorials</a>
				<a href="http://www.tutorialstream.com"><img src="/images/tstream.gif" align="right" width="88px" height="31px" border="0" alt="Tutorial Stream" /></a>
		</div>

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

and heres my .htaccess file just in case
RewriteEngine On
RewriteRule ^axsu/(.*)/(.*)\.axsu$ index.php?id=$id&page=$page

EDIT: oh and the tutorials link is in another folder within the mods directory, how would i get that link to be /axsu/tutorials? and if its possible i would really want the links to be /about/, /contact/, and so on...

Edited by zetsumei, 14 August 2006 - 06:56 PM.


#15 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 14 August 2006 - 07:08 PM

Quote

		<div id="nav">
				<a href="/">Home</a> <a href="/axsu/about/about.axsu">About</a> <a href="/axsu/contact/contact.axsu">Contact</a>
				<a href="/axsu/port/port.axsu">Portfolio</a> <a href="?id=tutorials&page=viewtut">Tutorials</a>
				<a href="http://www.tutorialstream.com"><img src="/images/tstream.gif" align="right" width="88px" height="31px" border="0" alt="Tutorial Stream" /></a>
		</div>

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

and heres my .htaccess file just in case
RewriteEngine On
RewriteRule ^axsu/(.*)/(.*)\.axsu$ index.php?id=$id&page=$page

EDIT: oh and the tutorials link is in another folder within the mods directory, how would i get that link to be /axsu/tutorials? and if its possible i would really want the links to be /about/, /contact/, and so on...

Here's your new .htaccess file, you have your variables completely wrong. It doens't use them like that. It assigns them numbers.

RewriteEngine On
RewriteRule ^axsu/(.+)/(.+)\.axsu$ /index.php?id=$1&page=$2 [nc]
RewriteRule ^(.+)/$ /index.php?id=$1 [nc]

Also you needed '+' to tell it 'one or more of'. I would thinkg 'zero or more of' would give you some wierd results. :)
I also added the rule you were asking about in your edit.
The '[nc]' makes it not case-sensitive also. :)

Edited by Demonslay, 14 August 2006 - 07:08 PM.


#16 zetsumei

    Young Padawan

  • Publishing Betazoids
  • Pip
  • 269 posts
  • Gender:Male
  • Location:127.0.0.1

Posted 14 August 2006 - 07:10 PM

EDIT: i have it fully working now thanks to demonslay and everyone else who helped XD...

Edited by zetsumei, 14 August 2006 - 08:46 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users