I need to redirect everything (www.example.com/, www.example.com/en/, www.example.com/en/index.php?do=xyz, etc.) to index.php, but I can't get everything working.

1st try:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ /index.php?path=$1 [NC,L,QSA]

works, but stylesheets href="css/xyz.css" don't load if I use www.example.com/en/. I would need to change them to href="/css/xyz.css" and I won't.

2nd try:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]{2})/(.*) $2 [QSA]
RewriteRule ^([^/]*)$ index.php?op=$1 [L,NS,QSA]

This works, CSS files are ok, the only bad thing is that jquery $.get can't find the files so I think I am missing something on the way. And maybe I could do everything using only one RewriteRule?

Any suggestion?


After some trys and searches I got it working using:

RewriteCond %{DOCUMENT_ROOT}/$2 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/$2 -d
RewriteRule ^([a-z]{2})/(.+)$ /$2 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
|improve this answer|||||
  • Isn't that always the way? You fiddle around with something forever, finally give up and post a question, then figure it out afterwards. We have all done this. It seems to be a necessary part of the process. I am glad you got it!! – closetnoc Jan 31 '16 at 3:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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