Ok, I've wasted a lot of time trying to figure this out but the more I'm trying to learn about rewriting rules, the less I seem to understand what's going on. I need to fix some rewriting rules for a codeigniter based project.
The application is a multilanguage CMS that basically works with modules, pages and posts and in a .htaccess file I need to check if the url is a page or a post and redirect to a appropriate controller.
So far in my .htaccess file i have the following:
#if I'm on the homepage and i have a language id
RewriteCond $1 ^([a-z]{2})/?$
RewriteRule ^(.*)$ index.php?homepage/index/$1 [PT,L]
#if module - this works ok when there is no language id
RewriteCond $1 ^(gallery|post|products)
RewriteRule ^(.*)$ index.php?$1 [PT,L]
# Rewrite all other URLs to index.php/URL - page controller
RewriteRule ^(.*)$ index.php?page/show/$0 [PT,L]
With the code above, if I enter
http://mydomain.com/gallery/something/9
everything is fine and dandy, dut if I add a language id like so:
http://mydomain.com/en/gallery/something/9
it doesn't work anymore, and I get a page not found/404 error from the page controller (redirect at the end of .htaccess).
So let's say that i have urls that can look something like this:
http://mydomain.com/gallery/something/9
http://mydomain.com/en/gallery/something/25
http://mydomain.com/fr/post/something/31
I need to somehow redirect those urls to
http://mydomain.com/gallery/something/9
http://mydomain.com/en/gallery/somethingelse/25
http://mydomain.com/fr/post/somethingelse/31
Notice that sometimes I have language id, and sometimes I don't. Is this something that I should be doing by using htaccess? Is Codeigniter routing a better alternative? Thank you for any help Stack Overflow :)
Try that:
RewriteCond $1 ^[^/]*/?(gallery|post|products)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With