Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite challenged need help

Need help with mod_rewrite

         

pinkopanter

4:47 am on Jan 25, 2006 (gmt 0)

10+ Year Member



Hi,

Here is my .htaccess file

RewriteEngine on
RewriteRule ^category(.*).html$ index.php?page=category&category_id=$1 [L]
RewriteRule ^article(.*).html$ index.php?page=article&article_id=$1 [L]
RewriteRule ^page_(.*).html$ index.php?pagedb=$1 [L]
RewriteRule ^categories.html$ index.php?page=allcategory
RewriteRule ^index.html$ index.php

Also I need to rewrite the following line
[mysite.com...]

to look like

[mysite.com...]

Please help
Thanks
I

jd01

1:27 am on Jan 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It looks like your last example is going the wrong way... You will need to link to the static URL and then serve the information from the dynamic.

The other problem it looks like you are going to run into is: the first rule will match the pattern you have specified in the rule you would like to add.

Without more information about why your rules are written the way they are, there is not much information we can give you. You might want to have a look in the Apache Library (link at the top left of the pages) to get a working knowledge of mod_rewrite and regular expressions...

Justin

extras

3:23 pm on Jan 26, 2006 (gmt 0)

10+ Year Member



Probably, the example is correct, and the way he asked the other one isn't.

Personally, I don't think it's a good idea to use something we don't understand well and/or we can't maintain by ourselves.

Too many people are using "Short URL" type of things without really knowing what to do
and ask these questions expecting someone to write the code for them (and for free...).

Unfortuantely, RewriteRules are not very easy, and influenced by many factors.
Most of the time, it would be easier to parse and treat URL in the script, like Drupal and some other CMSs do.

Also, by using prefix (or other methods), the use of !-f and !-d can be avoided to reduce the processing cost.
Example:
RewriteRule ^prefix(.*)$ index.cgi [L]