Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite Problem

Simple mod rewrite query

         

Weirfire

8:42 pm on Sep 12, 2005 (gmt 0)

10+ Year Member



I've been trying to learn mod rewrite for the last couple of weeks and am finding it fairly difficult to come to terms with what symbols are meant to go where.

I'm trying to get a very simple rewrite to work which is as follows;

What I want to do is turn

domain.com/this-text

into

domain.com/page.php?a=this-text

This is my code so you can tell me how wrong I was

<IfModule mod_rewrite.c>
Options +Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule /(.*)$ page.php?a=$1 [L]
</IfModule>

jdMorgan

8:50 pm on Sep 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your code says, "rewrite slash followed by <anything> to page.php?a=<anything>"
So it may create a loop, since page.php can match <anything> and be rewritten in turn to "page.php?a=page.php"

What are the results of your testing?
How do these results differ from what you expect/desire?

Jim

Weirfire

8:55 pm on Sep 12, 2005 (gmt 0)

10+ Year Member



That is exactly what it's doing!

Thanks for figuring that out 6 hours quicker than me lol. Do I need to write a condition for page.php to stop it rewriting?

jdMorgan

10:49 pm on Sep 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, you need to either make the RewriteRule pattern more specific to "allow" only certain requests to be rewritten, or add RewriteConds to prevent requests for page.php, robots.txt, custom errordocument, image, css, and external JS files (as applicable) from being rewritten. Which is more efficient depends on your current site structure and your future plans.

The exclusion list I present is a minimum; You may have many other files that should not be rewritten for efficiency's sake.

Jim