TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   mod_rewrite (http://www.talkphp.com/general/2570-mod_rewrite.html)

TlcAndres 04-02-2008 02:54 PM

mod_rewrite
 
Well I've worked with it before but this time it's just not cooperating. I need to turn this..

http://domain.com/index.php/member/foo/this

into

http://domain.com/index/member/foo/this

I got the impression it would be something like this
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)$ $1/

delayedinsanity 04-02-2008 03:10 PM

I may be wrong about this, but shouldn't it be the other way around?

RewriteEngine On
RewriteRule ^/([A-Za-z]+)/ /$1.php

Salathe 04-02-2008 05:42 PM

You'll probably want something more along the lines of:
Code:

<IfModule mod_rewrite.c>
        RewriteEngine On

        # Redirect all requests to index.php
        # if file doesn't exist
        # and directory doesn't exist

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

</IfModule>

The RewriteCond lines make sure that the rewriting only happens if the URL is not otherwise normally accessible (useful for images, CSS, etc.). The RewriteRule line rewrites URIs starting with index/ as you requested.

marxx 04-02-2008 05:52 PM

Well, do there really have to show that index?

ie.
Code:

http://domain.com/member/foo/this
and we call it like this
Code:

http://domain.com/index.php?mode=member&cat=foo&do=this
We put htaccess like this

Code:

RewriteEngine On

RewriteRule ^/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.php?mode=$1&cat=$2&do=$3 [QSA,L]

I don't know how familiar you are whit mod_rewrite so I try explain something about that.
In the end you find those tags, if I recall correct QSA allows more definitions in url end (domain.com/member/foo/this/?newdef=likethis)
and L says that rule ends there.

If you like, you can do all your files look like "folders".. Well I put some examples bellow:

Code:

http://domain.com/customers.php => http://domain.com/customers/
or

Code:

http://domain.com/folder/mypanel.php => http://domain.com/folder/mypanel/
do

Code:

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

As you can see, the are those tags again so you can add more definitions in urls end if you like or add new rules in htaccess.

Hope these help you and please don't kill me if won't work as it is presented in your system. Those should because I use them ATM! ;)

Aaron 04-02-2008 08:41 PM

I never really got mod_rewrite, do those codes work for every variable, or do you need to change it depending on the get variables you want to pass?


All times are GMT. The time now is 07:28 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0