1

I want to do this: (firstly, ci is my codeigniter folder)
If user call ci/2012.htm I want to redirect ci/oyna/oyun/2012.htm I'm trying to use this but It's not running.

    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    RewriteRule ^(.*)$ index.php/oyna/oyun/$1 [L,QSA]

When I call ci/2012.htm it returns codeigniter 404 not found page.

5
  • Is the line feed between on and RewriteCond missing in your real file, or just a copy/paste mistake? Commented Sep 8, 2012 at 13:33
  • I'm really new for htaccess. I need help. Commented Sep 8, 2012 at 13:38
  • @JoachimIsaksson copy/paste mistake :) Commented Sep 8, 2012 at 13:49
  • You may want to clarify your question a bit, are you trying to redirect all requests .htm files to static files in that folder and avoiding passing them through codeigniter (ie without passing them through index.php)? Commented Sep 8, 2012 at 14:14
  • @JoachimIsaksson when I call ci/oyna/oyun/2012.htm it returns true things. Commented Sep 8, 2012 at 14:21

1 Answer 1

1

First; you have two rewriterules that conflict for the rewrite you're making;

RewriteRule ^(.*)$ index.php/$1 [L,QSA]
RewriteRule ^(.*)$ index.php/oyna/oyun/$1 [L,QSA]

The L flag indicates that if a rule matches, the next rules won't be used. Since 2012.htm matches the first rule (both rules match everything), it will be rewritten to index.php/2012.htm and stop there, not even getting to your oyna/oyun rewrite.

The solution would be to swap the rules and make the .htm rewrite more specific so it only rewrites .htm files. Changing the rule to;

RewriteRule ^(.*\.htm)$ index.php/oyna/oyun/$1 [L,QSA]

should work better.

The result, after putting the most selective rule first, should look something like (untested, no apache here)

EDIT: Added missing RewriteCond, you need one per RewriteRule

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*\.htm)$ index.php/oyna/oyun/$1 [L,QSA]
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Sign up to request clarification or add additional context in comments.

4 Comments

Result: Internal Server Error ?
@user1648692 Sorry, added a missing RewriteCond, there needs to be one per RewriteRule.
same. And now it can't reach css files.
@user1648692 Depending on where your css files are stored (and at what path they're fetched), you may need to put back the RewriteCond %{REQUEST_FILENAME} !-fand RewriteCond %{REQUEST_FILENAME} !-d. And with "same", do you mean internal server error? I just got to a machine where I could test the setup and with a cut'n'paste from above I get the correct redirect without any errors.

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.