Jump to content


Clean URL


23 replies to this topic

#1 BlazeForc3

    Young Padawan

  • Members
  • Pip
  • 62 posts
  • Location:Australia

Posted 11 August 2006 - 08:35 AM

Im not sure exactly but I imagine the main scripting language P2L uses for displaying tutorials etc.. is php just wondering how such a clean URL is achieved:

http://www.pixel2lif...arch/all/sig/1/

instead of having something like:

http://www.pixel2life.com/index.php?search...=all&page=1

#2 Matthew.

    Official Spammer .Matt

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

Posted 11 August 2006 - 08:51 AM

Its called mod_rewrite :P Its achually an apache module.

^_^ http://www.google.co.uk/search?hl=en&s...ite&spell=1

The sitepoint article is quite helpful. http://www.sitepoint...e-url-rewriting

Edited by .Matt, 11 August 2006 - 08:52 AM.


#3 BlazeForc3

    Young Padawan

  • Members
  • Pip
  • 62 posts
  • Location:Australia

Posted 11 August 2006 - 09:16 AM

Thanks for that :) i didnt know it was called mod_rewrite

#4 Hayden

    P2L Jedi

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

Posted 11 August 2006 - 10:54 AM

Here's a mod_rewrite generator that I found using Google that helps to write the rules.

:)

#5 Indigo

    Official Alien

  • Members
  • PipPipPip
  • 617 posts
  • Gender:Male
  • Location:Trondheim, Norway
  • Interests:Computing in general, especially design and programming of all kinds.

Posted 12 August 2006 - 08:16 AM

You should add that one to the resource-forum here, it might be helpful to some (including me, when I need to change my url's)

#6 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 12 August 2006 - 09:51 AM

is it me or does that generator not work??? I type all the things in and the page refresh's and nothing...

Matt

#7 Hayden

    P2L Jedi

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

Posted 12 August 2006 - 10:03 AM

View Postdeadly, on Aug 12 2006, 02:50 PM, said:

is it me or does that generator not work??? I type all the things in and the page refresh's and nothing...

Matt

weird. :D

I've never had a problem with it.


Do you have any sort of firewall of some sort on at all?

still odd though, as I have Norton Internet Security on and it works. :blink:

Edited by SpatialVisionary, 12 August 2006 - 10:04 AM.


#8 Koncept

    Young Padawan

  • Members
  • Pip
  • 41 posts

Posted 12 August 2006 - 07:52 PM

Here is how i would do it
/**
 * handle.php
 */
$parts = preg_split('~/~', $_GET['path'], -1, PREG_SPLIT_NO_EMPTY);
if(isset($parts[0])) ? include_once($parts[0]) : include_once('index.php');
.htaccess
<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteRule ^(.*)$ handle.php?path=$1 [QSA,L]
</IfModule>

Something like that... That may or may bot be exactly what you want.

^_^

#9 BlazeForc3

    Young Padawan

  • Members
  • Pip
  • 62 posts
  • Location:Australia

Posted 26 August 2006 - 08:46 PM

Sorry to bump an old topic but i just got around to trying this and ive got a problem, it seems like mod_rewrite and my relative image links are not getting along.

eg. /css/images/image.gif
should be: http://www.url.com/c...mages/image.gif
but with mod_rewrite i get: http://www.url.com/h...mages/image.gif

This is my rewrite rule:

RewriteEngine On
RewriteRule (.*)/$ /skins/index.php?do=$1

#10 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 26 August 2006 - 08:56 PM

Well, it shouldn't do that, but try this for you rewrite rule just incase.

RewriteEngine On
RewriteRule ^(.*)/$ /skins/index.php?do=$1 [nc]


#11 BlazeForc3

    Young Padawan

  • Members
  • Pip
  • 62 posts
  • Location:Australia

Posted 26 August 2006 - 09:52 PM

View PostDemonslay, on Aug 27 2006, 01:56 AM, said:

Well, it shouldn't do that, but try this for you rewrite rule just incase.

RewriteEngine On
RewriteRule ^(.*)/$ /skins/index.php?do=$1 [nc]

nope still not working

#12 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 26 August 2006 - 09:55 PM

Link to your site please?

#13 BlazeForc3

    Young Padawan

  • Members
  • Pip
  • 62 posts
  • Location:Australia

Posted 26 August 2006 - 10:05 PM

Its ok i figured out the problem, because the site is in a folder not the root directory i had to change my image links...

i had my links as css/images/image.gif for example but they needed to be /skins/css/images/image.gif works good now thanks for your help anyway

one other thing say one of my pages has an extra parameter so $id=something but all the rest dont so for example:

Pages with 1 param:
http://www.url.com/index.php?do=home --> http://www.url.com/home/
http://www.url.com/i...hp?do=tutorials --> http://www.url.com/tutorials/

Page with 2 params:
http://www.url.com/i...p?do=skins&id=1 --> http://www.url.com/skins/1/

With the following rewrite rule only the page with 2 params worked correctly:

RewriteEngine On
RewriteRule ^(.*)/(.*)/$ /skins/index.php?do=$1&id=$2 [nc]

And of course with the rewrite rule below only the pages with 1 param worked:

RewriteEngine On
RewriteRule ^(.*)/$ /skins/index.php?do=$1 [nc]

How do i go about having 1 rule to fit both situations if thats possible?

Edited by BlazeForc3, 27 August 2006 - 12:00 AM.


#14 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 27 August 2006 - 12:05 AM

RewriteEngine On
RewriteRule ^(.*)/(.*)/$ /skins/index.php?do=$1&id=$2 [nc]
RewriteRule ^(.*)/$ /skins/index.php?do=$1 [nc]

Always have the rules with the most params first, other wise you will get 404 errors and the whatnot. :P

Edited by Demonslay, 27 August 2006 - 12:05 AM.


#15 pirateXcore

    Young Padawan

  • Members
  • Pip
  • 281 posts
  • Gender:Male

Posted 14 November 2006 - 10:57 AM

I'm going to be bumping this topic as well.
I had made a topic before, and i've done everything right, but mod_rewrite just won't work for me.
I get a SQL error with it. So tell me, if I have something that has a relative link back to something and I use mod rewrite and it changes the link to news/1/2.html would this confilct with what I have for the relative link, and would it possibly be the reason for the SQL error. (I'll post the error when I get out of school if it'd be helpful)
Thanks

#16 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 14 November 2006 - 02:12 PM

mod_rewrite cannot cause mysql errors as far as i know, try accessing your fiel with the direct link and see if it works. If it doesn't create a new topic and post your code and the mysql_error your receiving.

#17 pirateXcore

    Young Padawan

  • Members
  • Pip
  • 281 posts
  • Gender:Male

Posted 14 November 2006 - 11:35 PM

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'news/1,5' at line 1

that is the error

#18 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 15 November 2006 - 03:08 PM

Be sure you are giving it the correct variables to pass to the script, and be sure they are named exactly what they should be.
Are you getting this error when you access the script with the usual way, of using the long URL (site.com/page.php?var=1&id=2...). If not, then you are probably not passing the variables correctly, or are giving invalid values.
Show us the exact links, both longated, and relative, and we can compare the two and see why it is giving the 'news/' to the LIMIT (I assume).
I also suspect you may be doubling your variables. For instance, if you have your index page grabbing the 'id' to include a page, and you are adding an 'id' for the news article, they will conflict and you will get some contrasting results.

#19 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 15 November 2006 - 03:38 PM

I don't know what 'L' means, though I use it all the time, so maybe you could tell me what that means in exchange? Lol.

I know 'nc' is basially non-case-sensitive, so something like 'site.com/example/1' and 'site.com/Example/1' will both still work the same. ^_^

Edited by Demonslay, 15 November 2006 - 03:39 PM.


#20 pirateXcore

    Young Padawan

  • Members
  • Pip
  • 281 posts
  • Gender:Male

Posted 15 November 2006 - 07:04 PM

View PostDemonslay, on Nov 15 2006, 12:08 PM, said:

Be sure you are giving it the correct variables to pass to the script, and be sure they are named exactly what they should be.
Are you getting this error when you access the script with the usual way, of using the long URL (site.com/page.php?var=1&id=2...). If not, then you are probably not passing the variables correctly, or are giving invalid values.
Show us the exact links, both longated, and relative, and we can compare the two and see why it is giving the 'news/' to the LIMIT (I assume).
I also suspect you may be doubling your variables. For instance, if you have your index page grabbing the 'id' to include a page, and you are adding an 'id' for the news article, they will conflict and you will get some contrasting results.
http://punkbythebook...hp?news=1&id=22
http://punkbythebook.../news/1/22.html
Here are the links.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users