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.
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]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.