Help converting .htaccess

 
Post new topic   Reply to topic    Aprelium Forum Index -> URL Rewriting
View previous topic :: View next topic  
Author Message
littlebigfred
-


Joined: 02 Dec 2006
Posts: 12

PostPosted: Wed Jan 24, 2007 10:39 pm    Post subject: Help converting .htaccess Reply with quote

Hello

I'm trying to learn the Code Igniter framework to write web apps in PHP. It requires using an .htaccess to remove index.php from the URL to get cleaner addresses (eg. http://localhost/index.php/myctrl to http://localhost/myctrl).

Would an experienced and kind soul tell me how to rewrite the following file to its equivalent in Abyss X1?

Code:

RewriteEngine on
RewriteRule ^$ index.php [L]
RewriteCond $1 !^(index\.php|assets|search)
RewriteRule ^(.*)$ index.php/$1 [L]


Thanks !
Back to top View user's profile Send private message
hc2995
-


Joined: 07 Aug 2006
Posts: 644
Location: Maryland, USA

PostPosted: Thu Jan 25, 2007 1:41 am    Post subject: Reply with quote

I believe this is done with the url re-writing, it is to my knowledge that abyss does not use .htaccess files, incase the URL re-writing dosent work
_________________
Where have i been? School got heck-tick, had to move half way around the state, then back... and then i had to change jobs, so iv been away for a while :P
Back to top View user's profile Send private message AIM Address
littlebigfred
-


Joined: 02 Dec 2006
Posts: 12

PostPosted: Thu Jan 25, 2007 7:31 am    Post subject: Reply with quote

hc2995 wrote:
I believe this is done with the url re-writing, it is to my knowledge that abyss does not use .htaccess files, incase the URL re-writing dosent work


Thanks. Turns out that the latest version of Abyss (2.4) supports URL rewriting, although not through .htaccess, so I must understand what the above means. FWIW, I found it in the archives in the CI forum, as the one given in the online documentation didn't work for me.

Can someone confirm that
Code:
RewriteRule ^$ index.php [L]
means that any URL for the directory in which .htaccess is located that doesn't have index.php explicitely written, eg. http://localhost/igniter, will be replaced with http://localhost/igniter/index.php?

And as far as the second part is concerned, I googled for RewriteCond, but didn't find an explanation as to what $1 stands for in
Code:
RewriteCond $1 !^(index\.php|assets|search)
: Does it refer to the entire URL?

If yes, I understand that it means that if it doesn't find either "index.php", "assets", or "search" in the URL, then it will be rewritten by prepending index.php to the URI.

Thanks.
Back to top View user's profile Send private message
littlebigfred
-


Joined: 02 Dec 2006
Posts: 12

PostPosted: Thu Jan 25, 2007 9:41 am    Post subject: Reply with quote

More information to investigate: URL Rewriting doesn't even work with the following basic example:

/toto/ Perform an internal redirection /titi/ Stop matching

Virtual Path Regular Expression = /toto/
Conditions = Empty
If this rule matches = Perform an internal redirection
Redirect to = /titi/

I get a Error 500 Internal Server Error

FWIW, /www/titi/ does exist and contains an index.html :-/
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Thu Jan 25, 2007 11:31 am    Post subject: Reply with quote

littlebigfred,

Turn URL rewriting logging/debugging on to understand what's going on and how your request is being interpreted/translated.

In

Code:
RewriteCond $1 !^(index\.php|assets|search)


$1 is backreference resulting from matching the RewriteRule so it could be replaced by ${REQUEST_URI} (since the RewriteRule regular expression is ^(.*)$ ).
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
littlebigfred
-


Joined: 02 Dec 2006
Posts: 12

PostPosted: Thu Jan 25, 2007 2:04 pm    Post subject: Reply with quote

aprelium wrote:
Turn URL rewriting logging/debugging on to understand what's going on and how your request is being interpreted/translated.


Thanks, I didn't see I could log those. Turns out that REQUEST_URL didn't work, and I should use REQUEST_URI. The redirection with /toto/ and /titi/ works now :-)

aprelium wrote:
Code:
RewriteCond $1 !^(index\.php|assets|search)


$1 is backreference resulting from matching the RewriteRule so it could be replaced by ${REQUEST_URI} (since the RewriteRule regular expression is ^(.*)$ ).


I'm puzzled about $1 here. Here's a simplified alternative that I saw mentionned in the Code Igniter forum:

Code:

RewriteEngine on

RewriteRule ^$ index.php [L]   <- no ()!!!

RewriteCond $1 !^(index\.php|assets|search)  <- $1 ???
RewriteRule ^(.*)$ index.php/$1 [L]


Does it mean that $1 is referring to the RewriteRule on the line right above it? How come?

I finally got Code Igniter to work with the following:

^/igniter/(.*)$
//Note the ? after index.php
Perform an internal redirection /igniter/index.php?/$1
Continue with the next rule

BTW, out of curiosity, how would I do the following with Abyss:

Code:

    RewriteEngine On

    RewriteBase /

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


Thanks!
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Fri Jan 26, 2007 11:19 am    Post subject: Reply with quote

[quote="littlebigfred"]Does it mean that $1 is referring to the RewriteRule on the line right above it? How come?[quote]

That's the magic of mod_rewrite syntax. A vague explanation of that is available in its manual and reading the source code of the module shows that it processes the RewriteRule first, sets backreferences, and then makes them available when validating conditions.

Code:

    RewriteEngine On

    RewriteBase /

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


The conversion of that rule is straightforward: Create a new rule as follows:
* Virtual Path regular expression: ^(.*)$
* Conditions:
- Condition 1:
REQUEST_FILENAME is not a file
- Condition 2:
REQUEST_FILENAME is not a directory
* Set "If this rule matches" to "Perform an internal redirection"
* Set "Redirect to" to /index.php/$1
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
loloyd
-


Joined: 03 Mar 2006
Posts: 435
Location: Philippines

PostPosted: Fri Feb 02, 2007 8:28 am    Post subject: Reply with quote

Congratulations, Aprelium. My websites at the office internal LAN work phenomenally flawless and so I don't get to visit back here much often anymore. I'd be willing to lend a helping hand in the following days and weeks as time permits, especially in the areas of URL-rewrites whenever I can. maybe you can set you can set up a different topical forum devoted to setting up URL-Rewrites?
_________________

http://home.loloyd.com/ is online if the logo graphic at left is showing.
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> URL Rewriting All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group