• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
mod_rewrite changing URI segment order

#1
[eluser]Resorath[/eluser]
Hi,

I am trying to make apache mod_rewrite move the third (first parameter of codeigniter) to the front of the URL. In my example case, I have the "variable name" as the first parameter of the URI, followed by the usual pattern of controller, method and additional parameters.

So in the case of:
http://www.example.com/myname/controller/method/1/2/

It would be rewritten to

http://www.example.com/controller/method/myname/1/2

My mod_rewrite rule seems to be doing the job, but codeigniter gives me a "404 Page Not Found" when trying to use the URL.

Here is my htaccess file (with most of the lines from the wiki omitted for clarity):

Code:
RewriteEngine On
    RewriteBase /mysite/

...

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$         index.php?/$2/$3/$1    [L]  
    RewriteRule ^(.*)$ index.php?/$1 [L]

This appears to work correctly when I turn on mod_rewrite logging (lines trimmed for clarity):

(In this case, the url is http://localhost/firstweddingsite/home/runsite/, where ultimately, "firstweddingsite" is to become a parameter, "home" is a controller and "runsite" is a function that accepts the parameter "firstweddingsite")

Code:
[rid#5358118/initial] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] add path info postfix: E:/xampp/htdocs/unnamedweddingsite/firstweddingsite -> E:/xampp/htdocs/unnamedweddingsite/firstweddingsite/home/runsite/
[rid#5358118/initial] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] strip per-dir prefix: E:/xampp/htdocs/unnamedweddingsite/firstweddingsite/home/runsite/ -> firstweddingsite/home/runsite/
[rid#5358118/initial] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] applying pattern '^(.*)$' to uri 'firstweddingsite/home/runsite/'
[rid#5358118/initial] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] add path info postfix: E:/xampp/htdocs/unnamedweddingsite/firstweddingsite -> E:/xampp/htdocs/unnamedweddingsite/firstweddingsite/home/runsite/
[rid#5358118/initial] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] strip per-dir prefix: E:/xampp/htdocs/unnamedweddingsite/firstweddingsite/home/runsite/ -> firstweddingsite/home/runsite/
[rid#5358118/initial] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] applying pattern '^(.*)$' to uri 'firstweddingsite/home/runsite/'
[rid#5358118/initial] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] add path info postfix: E:/xampp/htdocs/unnamedweddingsite/firstweddingsite -> E:/xampp/htdocs/unnamedweddingsite/firstweddingsite/home/runsite/
[rid#5358118/initial] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] strip per-dir prefix: E:/xampp/htdocs/unnamedweddingsite/firstweddingsite/home/runsite/ -> firstweddingsite/home/runsite/
[rid#5358118/initial] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] applying pattern '^([^/]+)/([^/]+)/([^/]+)/?$' to uri 'firstweddingsite/home/runsite/'
[rid#5358118/initial] (2) [perdir E:/xampp/htdocs/unnamedweddingsite/] rewrite 'firstweddingsite/home/runsite/' -> 'index.php?/home/runsite/firstweddingsite'
[rid#5358118/initial] (3) split uri=index.php?/home/runsite/firstweddingsite -> uri=index.php, args=/home/runsite/firstweddingsite
[rid#5358118/initial] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] add per-dir prefix: index.php -> E:/xampp/htdocs/unnamedweddingsite/index.php
[rid#5358118/initial] (2) [perdir E:/xampp/htdocs/unnamedweddingsite/] trying to replace prefix E:/xampp/htdocs/unnamedweddingsite/ with /unnamedweddingsite/
[rid#5358118/initial] (1) [perdir E:/xampp/htdocs/unnamedweddingsite/] internal redirect with /unnamedweddingsite/index.php [INTERNAL REDIRECT]
[rid#536acb0/initial/redir#1] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] strip per-dir prefix: E:/xampp/htdocs/unnamedweddingsite/index.php -> index.php
[rid#536acb0/initial/redir#1] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] applying pattern '^(.*)$' to uri 'index.php'
[rid#536acb0/initial/redir#1] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] strip per-dir prefix: E:/xampp/htdocs/unnamedweddingsite/index.php -> index.php
[rid#536acb0/initial/redir#1] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] applying pattern '^(.*)$' to uri 'index.php'
[rid#536acb0/initial/redir#1] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] strip per-dir prefix: E:/xampp/htdocs/unnamedweddingsite/index.php -> index.php
[rid#536acb0/initial/redir#1] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] applying pattern '^([^/]+)/([^/]+)/([^/]+)/?$' to uri 'index.php'
[rid#536acb0/initial/redir#1] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] strip per-dir prefix: E:/xampp/htdocs/unnamedweddingsite/index.php -> index.php
[rid#536acb0/initial/redir#1] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] applying pattern '^(.*)$' to uri 'index.php'
[rid#536acb0/initial/redir#1] (2) [perdir E:/xampp/htdocs/unnamedweddingsite/] rewrite 'index.php' -> 'index.php?/index.php'
[rid#536acb0/initial/redir#1] (3) split uri=index.php?/index.php -> uri=index.php, args=/index.php
[rid#536acb0/initial/redir#1] (3) [perdir E:/xampp/htdocs/unnamedweddingsite/] add per-dir prefix: index.php -> E:/xampp/htdocs/unnamedweddingsite/index.php
[rid#536acb0/initial/redir#1] (1) [perdir E:/xampp/htdocs/unnamedweddingsite/] initial URL equal rewritten URL: E:/xampp/htdocs/unnamedweddingsite/index.php [IGNORING REWRITE]

It appears to be rewriting the URL (given by "rewrite 'firstweddingsite/home/runsite/' -> 'index.php?/home/runsite/firstweddingsite'")


codeigniter log just gives:

Code:
ERROR - 2012-07-04 07:11:16 --> 404 Page Not Found --> firstweddingsite

Is my rewrite working incorrectly, or is codeigniter not accepting the rewrite in the way that I expected?

Thanks!


Messages In This Thread
mod_rewrite changing URI segment order - by El Forum - 07-03-2012, 10:26 PM
mod_rewrite changing URI segment order - by El Forum - 07-03-2012, 11:36 PM
mod_rewrite changing URI segment order - by El Forum - 07-04-2012, 09:51 AM
mod_rewrite changing URI segment order - by El Forum - 07-04-2012, 10:24 PM
mod_rewrite changing URI segment order - by El Forum - 07-05-2012, 10:16 AM
mod_rewrite changing URI segment order - by El Forum - 07-05-2012, 11:44 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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