Results 1 to 10 of 10
-
06-12-2005, 06:57 AM #1Newbie
- Join Date
- Jan 2004
- Location
- Denmark
- Posts
- 21
Mod_rewrite help, can it be done?
Can the following be done with the use of Mod_rewrite?
I have the following URLs (with $variables):
domain.com/view.php?system=$row[system]&type=$row[type]&shortname$row[shortname]
example (without $variables);
domain.com/view.php?system=PC&type=Help&shortname=titlenamehere
With the help of Mod_rewrite I would like to make it look like this;
domain.com/PCHelp/titlenamehereHelp.htm
or
domain.com/PC-Help/titlenamehere-Help.htm
Is this possible?
-
06-12-2005, 07:13 AM #2Web Hosting Master
- Join Date
- Dec 2004
- Location
- Canada
- Posts
- 1,097
The second option should be quite simple, provided none of your possible system values has a dash in it.
-
06-12-2005, 12:52 PM #3Newbie
- Join Date
- Jan 2004
- Location
- Denmark
- Posts
- 21
Some people seems to have misunderstood my post, so i'll just try and explain it better;
have to use a .htaccess file ..
We need to be aware of changing variables.
This little piece of rewriting code partly does what im looking for, but not just quite (only to illustrate)
---
RewriteEngine On
RewriteRule ^([^./]+)/([^./]+)/([^./]+).htm$ view.php?system=$1&type=$2&shortname=$3 [L]
---
This would turn an original URL like;
domain.com/view.php?system=$system&type=$type&shortname=$shortname
into;
domain.com/$system/$type/$shortname.htm
However I want it turned into:
domain.com/$system$type/$shortname$type.htm
or
domain.com/$system-$type/$shortname-$type.htm
or atlast - without $type after $shortname at the end
-
06-12-2005, 01:29 PM #4Web Hosting Master
- Join Date
- Jul 2003
- Location
- Kuwait
- Posts
- 5,104
Err, mod_rewrite works the opposite way.
It rewrites The URL typed in the browser, to whatever you specify.
So your wording is not correct, but I hope your understanding of mod_rewrite isn't.
So what you really want mod_rewrite to do is take a URL such as domain.com/$system$type/$shortname$type.htm and rewrite it to view.php?system=$system&type=$type&shortname=$shortname
For this to happen, you need to write a regular expression that can distinguish between $system and $type -- this is why error404 said that the second option would be easier, because you can have the regular expression separate between the - in the $system-$key pattern.
-
06-12-2005, 01:37 PM #5Newbie
- Join Date
- Jan 2004
- Location
- Denmark
- Posts
- 21
Originally posted by fyrestrtr
So what you really want mod_rewrite to do is take a URL such as domain.com/$system$type/$shortname$type.htm and rewrite it to view.php?system=$system&type=$type&shortname=$shortname
I want to take a URL such as;
domain.com/view.php?system=$system&type=$type&shortname=$shortname
and rewrite it to
domain.com/$system$type/$shortname$type.htm
or
domain.com/$system-$type/$shortname-$type.htm
Sorry if i've expressed myself wrongly, my mistake :/
-
06-12-2005, 02:00 PM #6Web Hosting Master
- Join Date
- Jul 2003
- Location
- Kuwait
- Posts
- 5,104
So what do you want the user to type in the browser? the view.php?system= or the /$system-$type/ ?
-
06-12-2005, 02:18 PM #7Newbie
- Join Date
- Jan 2004
- Location
- Denmark
- Posts
- 21
I want the user to type in;
domain.com/$system$type/$shortname$type.htm
or
domain.com/$system-$type/$shortname-$type.htm
-
06-13-2005, 02:45 AM #8Web Hosting Master
- Join Date
- Jul 2003
- Location
- Kuwait
- Posts
- 5,104
This is what I thought. You then want to rewrite the domain.com/$system-$type/$shortname-$type.htm into view.php?
For this,
RewriteRule ^(.*?)-(.*?)/(.*?)-(.*?).htm$ view.php?system=$1&type=$2&shortname=$3&stype=$4.php
Should work, although its early.
-
06-13-2005, 07:19 AM #9Newbie
- Join Date
- Jun 2005
- Posts
- 14
mod rewrite
I heard theres a good site called doriat.com discussing about mod rewrite on php scripts.
-
06-14-2005, 04:13 PM #10Newbie
- Join Date
- Jan 2004
- Location
- Denmark
- Posts
- 21
fyrestrtr > got it working, thanks alot