• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
.htaccess rewrite rules

#1
[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

#2
[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

#3
[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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.