help on mod rewrite

New to mod_rewrite? This is a good place to start.

help on mod rewrite

Postby stathis » Wed Apr 28, 2004 4:42 am

Hello everyone. I need help on something.
I have a dynamic site which pages look something like:
http://www.foo.com/some_word.php?l=49
http://www.foo.com/some_word.php?l=2
http://www.foo.com/some_word.php?l=3

Can with mod rewrite to look like
http://www.foo.com/some_word/word1
http://www.foo.com/some_word/word2
http://www.foo.com/some_word/word3

Also i have some other pages who look like:
http://www.foo.com/some_word.php?l=49&d=7

How can i mod rewrite this?

I would appreciate any help
stathis
 
Posts: 2
Joined: Wed Apr 28, 2004 4:40 am

Postby Guest » Thu May 06, 2004 7:45 pm

RewriteEngine On
RewriteBase /
RewriteRule ^some_word/.*([0-9]+) /some_word.php?=$1

Just make your links like these

http://www.foo.com/some_word/word1
http://www.foo.com/some_word/word2
http://www.foo.com/some_word/word3

this will allow you to parse this
http://www.foo.com/some_word/word49

as if it were this

http://www.foo.com/some_word.php?=49 :wink2:
Guest
 

Postby Guest » Thu May 06, 2004 7:50 pm

as per the other urls just add a condition


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^some_word/.*([0-9]+)
RewriteRule ^some_word/.*([0-9]+) /some_word.php?=$1

RewriteCond %{REQUEST_URI} ^some_word/.*([0-9]+)-([0-9]+)
RewriteRule ^some_word/.*([0-9]+)-([0-9]+) /some_word.php?=$1&d=$2 [L]

Just like above
if your link is this
http://www.foo.com/some_word/word49-7

it will parse as if it were this

http://www.foo.com/some_word.php?l=49&d=7
Guest
 

HOW

Postby Beer Guy » Fri May 07, 2004 11:15 am

howcome when i go myfile/var1/var2 it works when parsing 2 variables.

but when i got myfile/var1 it will not display, this is annoying because im doing this with php


if($_GET[var1] AND !$_GET[var2]) {
stuff
}
elseif($_GET[var2] AND $_GET[var1] != "")
{

}
Beer Guy
 
Posts: 5
Joined: Fri May 07, 2004 11:07 am
Location: my computer

Postby seomike » Fri May 07, 2004 1:00 pm

if there are only 2 conditions then just do it like this

if($_GET[var1] AND $_GET[var2]) {
stuff
}
else{
stuff
}
seomike
 
Posts: 331
Joined: Thu May 06, 2004 7:36 pm
Location: Dallas

Postby Beer Guy » Fri May 07, 2004 1:13 pm

Im not asking about the php im asking about the mod rewrite, when i dont input 2 variables it wont display the page. it'll give me 404, i want to know how to avoid that.
Beer Guy
 
Posts: 5
Joined: Fri May 07, 2004 11:07 am
Location: my computer

Postby seomike » Fri May 07, 2004 4:35 pm

Try this

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^myfile/.*([0-9]+)
RewriteRule ^myfile/.*([0-9]+) /myfile.php?var1=$1

RewriteCond %{REQUEST_URI} ^myfile/.*([0-9]+)/.*([0-9]+)
RewriteRule ^myfile/.*([0-9]+)/.*([0-9]+) /myfile.php?var1=$1&var2=$2 [L]
seomike
 
Posts: 331
Joined: Thu May 06, 2004 7:36 pm
Location: Dallas

Postby Guest » Tue May 18, 2004 12:04 pm

how come this will only work with integers ranging from 1-9, if i increase it to do something like [0-5000] the same thing happens?
Guest
 

Postby seomike » Tue May 18, 2004 6:48 pm

[0-9] means match any number 0-9
seomike
 
Posts: 331
Joined: Thu May 06, 2004 7:36 pm
Location: Dallas

Postby Guest » Wed Jun 02, 2004 1:09 am

Well actually what i wanted was the other way around. Can it be done? I mean the name of the pages is dynamically generated eg.
http://www.foo.com/some_word.php?l=49
http://www.foo.com/some_word.php?l=2
http://www.foo.com/some_word.php?l=3

Is there a way that when someone (user or bot) follows these links to see something like:
http://www.foo.com/some_word/word1
http://www.foo.com/some_word/word2
http://www.foo.com/some_word/word3

Can it be done?
Guest
 


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 18 guests

cron