View Full Version : MOD_Rewrite


brainpulse
07-04-2004, 07:02 AM
IF have this link

links to xxx dot com are not permitted

I need to get this to something like


Can you please help

brainpulse
07-04-2004, 07:03 AM
This link posted above are generted dynamically.

xml
07-15-2004, 07:19 AM
You might wanna give an example of the dynamic url, and the static url you desire.

brainpulse
07-16-2004, 02:09 AM
I would want

http://www.domain.com/page.php?id=1&cat=category

to

http://www.domain.com/category.php


Please assist.

xml
07-17-2004, 03:29 AM
RewriteRule (.*).php /page.php?cat=$1

This will work as long as you don't have folders named the same as your category or, if you have 2 categories the same.

If you wanted it failsafe try:

RewriteRule (.*)/(.*).php /page.php?id=$1&cat=$2

owlcroft
07-17-2004, 03:24 PM
Better is to disguise altogether the php extension. The exact code would depend on to what extent you want to failsafe the characters used in category; if we assume, for discussion, that category must be entirely numeric, then you could use:

RewriteRule ^([0-9]+)\.html$ /category.php?id=1&cat=$1 [L]

That would rewrite a call of the form:
http://www.domain.com/73496.html

to a call to--

http://www.domain.com/category.php?id=1&cat=73496
A necessary assumption here is that you have no actual files in your root directory whose names are just some numerals followed by .html.

If category can be more complex than just numerals, then the term shown above as [0-9]+ would need to be a "regular expression" denoting the possible form. (For another example, if category were limited to capital letters and numerals, that term would be [0-9A-Z]+).

seo guy
07-19-2004, 12:11 AM
wow look at all the mod rewrite discussion that can be transfered to http://www.mod-rewrite.com/forum/ :)