6

I've got a RewriteRule like this:

RewriteRule ^thesection$ /sections.php [L]
RewriteRule ^thesection/(.*)$ /sections.php?show=$1 [L]

so, if I enter domain.com/thesection -> it works perfect

but!, if I enter domain.com/thesection/hello it redirects to domain.com/thesection?show=hello

I don't know what I'm doing wrong and I've spent hours googling. Please help!

Thanks in advance

2
  • What is domain.com/thesection/hello supposed to get rewritten to? Commented Dec 9, 2011 at 10:33
  • Hi Jon, domain.com/thesection/hello should be interpreted by the server as domain.com/sections.php?show=hello Thanks! Commented Dec 9, 2011 at 15:17

1 Answer 1

9

Try this and let me know

RewriteEngine On
RewriteRule ^thesection/?$ /sections.php [L,QSA]
RewriteRule ^thesection/([a-z0-9\-_]+)/?$ /sections.php?show=$1 [L,QSA]

this will redirect domain.com/thesection/hello to sections.php?show=hello

the QSA flag means:

This flag forces the rewrite engine to append a query string part of the substitution string to the existing string, instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule.

so you can add more parameters eg: http://www.domain.com/thesection/hello/?page=1 this will output:

Array (
 [show] => hello
 [page] => 1
)
Sign up to request clarification or add additional context in comments.

2 Comments

I don't know what I'm doing wrong but that didn't help. If I enter domain.com/thesection/hello, my browser redirects to domain.com/thesection?show=hello which is not the prettiest url ever seen. :( Thanks anyway, I've learned alot today.
Sorry, my bad. I had a configuration mistake. This worked perfectly, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.