Forum Moderators: phranque

Message Too Old, No Replies

rewrite issue beginner

mod rewrite issue with syntax

         

JayDev

3:09 pm on Jun 16, 2006 (gmt 0)

10+ Year Member



Hi,

I am new to mod_rewrite. I am trying to figure a simple htaccess file that I can't get to work.

here is the file:

RewriteEngine on
RewriteRule (.*)\.html$ main.php?subject=$1 [L]
RewriteRule (.*)\.html$ details.php?title=$1 [L]

The first rule works great but the second does not work. When I reverse the 2 rules, same thing, the 2nd does not work. I tried to go by a htaccess that was made for me but I can't succeed.

Any help is appreciated.

stapel

5:48 pm on Jun 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have the following code:

    RewriteEngine on

    RewriteRule (.*)\.html$ main.php?subject=$1 [L]

    RewriteRule (.*)\.html$ details.php?title=$1 [L]

I'm no authority, but it looks to me as though both of these Rewrite Rules apply to the same file types: those ending in ".html". As such, the server will process the .htaccess file, and (to my understanding) apply the first rule it encounters. Once the rewrite is done, the file name no longer ends with ".html", so the next rule will no longer apply.

What are you attempting to accomplish with these rules?

Thank you.

Eliz.

JayDev

7:45 pm on Jun 16, 2006 (gmt 0)

10+ Year Member



Thanks for the reply.

All I am trying to accomplish is to rewrite two php pages that I have.

1/ main.php with the url parameter subject

2/ details.php with the parameter title.

I am not sure how I am suppose to structure my htaccess file in order to achieve that goal.

In other words, 1/ should follow the rule subject.html
and 2/ should follow the rule title.html which you are right should be the same rule. However, how do you apply the same rule for two different php pages?

I guess that seems to be my problem.

stapel

11:14 pm on Jun 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't see how these rules would apply to different pages. They each appear to apply to "[anything].html".

The one rule takes "[anything].html" and converts it to, I think, "[anything].main.php" (with the query string tacked on at the end), and the other rule takes "[anything].html" and converts it to "[anything].details.php".

Whichever rule the server hits first is the only one processed, since the file name is changed after the first rule is applied.

There is so much I don't know, but I'm fairly certain that the RewriteRule syntax is "old_stuff new_stuff", so "[anything].html" is what you're converting from, not to.

Eliz.

Apache mod_rewrite [httpd.apache.org]
WebmasterWorld: Changing Dynamic URLs to Static URLs [webmasterworld.com]
WebmasterWorld: Changing dynamic to static URLs [webmasterworld.com]