: .htaccess file to implement multiple redirects 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_-+
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=&slug=
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=&slug=
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?
More posts by @Karen161
1 Comments
Sorted by latest first Latest Oldest Best
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 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=&slug=
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.