KTM
KTM

Reputation: 868

htaccess redirection in codeigniter

I have the following code in my .htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /annsenglishmediumschool
    RewriteCond %{HTTP_HOST} shops.annsenglishmediumschool.com
    RewriteRule .* http://annsenglishmediumschool.com/index.php/shops [L]    
</IfModule>

This works fine , but how can i make "shops" as a variable here ? means whatever we type in the place of "shops" should come after http://annsenglishmediumschool.com/index.php/ thanks in advance .

EDIT : after edit my .htaccess looks like this :

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /annsenglishmediumschool
    RewriteCond %{HTTP_HOST} ^(.+?)\.annsenglishmediumschool\.com$
    RewriteRule .* http://annsenglishmediumschool.com/index.php/%1 [L]
</IfModule>

The problem is that it now takes only 'www' to the right as annsenglishmediumschool.com/index.php/www ,and no other string ,any help is greatly thanked

Upvotes: 0

Views: 120

Answers (2)

Olaf Dietsche
Olaf Dietsche

Reputation: 74018

You can capture the part of the domain name you're interested in as %1 and use it in the RewriteRule

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(.+?)\.annsenglishmediumschool\.com$
RewriteRule .* http://annsenglishmediumschool.com/index.php/%1 [R,L]

If the host does not start with www., this grabs the first part of the domain (.+?) and puts it in the RewriteRule as %1.

When everything works as you expect, you can change R to R=301.

Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.

Upvotes: 1

akshayb
akshayb

Reputation: 1239

I think you are mixing two things. You can pass parameter directly to your controller to get the "shop" as variable.

for example :

index($variable){

echo $variable;

}

//It will echo $variable(shop this time) at yoursite.com/index.php/shop

Upvotes: 0

Related Questions