CodeIgniter Forums
.htaccess rewrite rules - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: .htaccess rewrite rules (/showthread.php?tid=53296)



.htaccess rewrite rules - El Forum - 07-18-2012

[eluser]obiron2[/eluser]
Guys,

My .htaccess file currently looks like this
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /ci/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>
Which I believe is the default configuration for most CI installations.

I have a controller called "scanned" with a method of "scanned" that takes a single argument "$code"

The URL should be www.mysite.com/scanned/scanned/CODE

Due to an oversight, documentation has gone out with www.mysite/scanned/CODE (i.e. missing the second "scanned"

I want to use mod_rewrite to add in the missing "scanned" but I can't work out the syntax.

I have tried
Code:
RewriteRule ^scanned/(.*)$ scanned/scanned/$1 [L]
and I have tried it before and after the index.php rewrite and with and without the [L]ast flag.

What am I doing wrong and can you explain to me what rewrite logic I have messed up


.htaccess rewrite rules - El Forum - 07-18-2012

[eluser]Aken[/eluser]
I would either A) Set up the rule as a redirect, not a rewrite (maybe include a note on the website about the correct URL, also), or 2) Use CI's built-in routing feature, rather than .htaccess


.htaccess rewrite rules - El Forum - 07-19-2012

[eluser]obiron2[/eluser]
Thanks Aiken, I ended up doing a Redirect 301 at the top of the file, but couldn't work out the regex to stop it repeating to the rewrite went to /found/keyed instead of scanned/scanned.

Loaded it all up to the live server and it isn't working - waiting for Tech support to tell me if mod_rewrite is set on. I will look at routes tonight.

Obiron