I have a dynamic site and from .htaccess file creating clean URLs:

RewriteCond %{REQUEST_URI}  !(\.png|\.jpg|\.gif|\.jpeg|\.bmp)$
RewriteRule ^([a-zA-Z0-9_\-\+\ ]+)$ flight.php?flights=$1&slug=$1

This code worked fine for me but when I created a new type of page and trying to get clean URLs with the same code i.e.:

RewriteCond %{REQUEST_URI}  !(\.png|\.jpg|\.gif|\.jpeg|\.bmp)$
RewriteRule ^([a-zA-Z0-9_\-\+\ ]+)$ manual-page.php?url=$1&slug=$1

it's not working and if I comment the previous two lines then its is working fine.

Only one code is working at a time.

For first I have a URL domain.com/flight.php?flight-san-fransisco-london-flights and I want this being redirect to domain.com/san-fransisco-london-flights & from the second one I have domain.com/manual-page.php?url=my-new-page and I want this being redirect to domain.com/my-new-page.

Is these any way to get both working together?

1 Answer 1


Your two RewriteRules match the exact same set of URL paths, and have the exact same RewriteCond, so it should be no surprise that the first one catches any matching paths and leaves nothing for the second one.

To fix this, you'd first need to decide how you're going to tell the two sets of URLs apart. That is, when the user's browser requests http://domain.com/my-new-page, how will your webserver know that this request should be handled by manual-page.php and not by flight.php?

Depending on how you decide to do that, you have a couple of options on the actual implementation:

  • If the difference can be expressed as a regexp, you can just change the first RewriteRule so that it won't match any URL paths that should be handled by the second one. For example, if all slugs for flight pages containg the word "flight", and none of those for the other pages do, the you could replace the first RewriteRule with:

    RewriteCond %{REQUEST_URI}  !(\.png|\.jpg|\.gif|\.jpeg|\.bmp)$
    RewriteRule ^([a-zA-Z0-9_\-\+\ ]*flight[a-zA-Z0-9_\-\+\ ]*)$ flight.php?flights=$1&slug=$1
  • Alternatively, you could have all requests first handled by, say, flight.php, and modify that script so that it calls manual-page.php if it can't find any matching page to display. Or you could write a single front-end script that takes all requests, checks a database to see which group they belong in, and calls the appropriate script to handle them.

  • Finally, if the scripts do more or less the same thing, with just minor differences, you might want to just combine them into a single script that can serve both kinds of pages.

  • can you please explain how i can achieve it as a whole. sorry i am pretty new to development
    – RobMorta
    Commented Jul 1, 2013 at 9:49
  • @RobMorta: As I said, first you need to decide how you're going to tell the two kinds of clean URLs apart. Come back once you've figured that out. Commented Jul 1, 2013 at 9:51
  • can you please suggest me some ways of doing this
    – RobMorta
    Commented Jul 1, 2013 at 10:00
  • No, not without more information from you, I can't. Answer me this: Imagine that I'm your webserver. Given the URL domain.com/my-new-page, how am I supposed to tell that it should be rewritten to manual-page.php rather than to flights.php? If you can tell me that, maybe I can tell you how to program your actual webserver to do it. Commented Jul 1, 2013 at 10:05
  • as of now there is no mechanism to do it, I know this is the pain point but don't know how to get out from it would you suggest me some logics to do it
    – RobMorta
    Commented Jul 1, 2013 at 10:43

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.