Mode-Rewrite

Using a single web hosting account to host multiple sites

Mode-Rewrite

Postby thebestmind » Fri May 02, 2008 10:31 am

Hello friends,

This is my first topic, please let me know if any problem with my post.

Let's I started now.

My site url now as following

http://site_name.com/en/controller_name/

I want to convert it as following

http://en.site_name.com/controller_name/

Language prefix is first and attached to domain name. So can you please tell me how can I solve this problem. Following is the my .htaccess file.

---------------------------------------htaccess file-------------------------------

RewriteEngine On
RewriteBase /

# Allow these directories and files to be displayed directly:
# - index.php (DO NOT FORGET THIS!)
# - robots.txt
# - favicon.ico
# - Any file inside of the media/ directory

RewriteCond $1 ^(index.php|robots.txt|favicon.ico|media|css)

RewriteRule ^(.*)$ - [PT,L]

# Force EVERY URL to contain a language in its first segment.
# Redirect URLs without a language to the invalid xx language.

RewriteCond $2 !^([a-z]{2}(/|$)) [NC]

RewriteRule ^(index\.php/?)?(.*)$ en/$2 [R=301,L]


# Silently prepend index.php to EVERY URL.
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php/$1 [L]

---------------------------------------htaccess file-------------------------------


Thanking you,

thebestmind.
thebestmind
 
Posts: 7
Joined: Fri May 02, 2008 10:24 am

Postby richardk » Sat May 03, 2008 4:16 pm

You need DNS for the sub domains. The server needs to be configured to send those sub domains to your current domain root, then you can use
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Files to ignore.
RewriteRule ^(index\.php|robots\.txt|favicon\.ico)$ - [L]
# Directories to ignore.
RewriteRule ^(media|css)(/.*)?$ - [L]

# Language sub domain to index.php.
RewriteCond %{HTTP_HOST} ^([a-z][a-z])\.example\.com$ [NC]
RewriteRule ^(.*)$ /index.php/%1/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Thanks for help

Postby thebestmind » Sat May 03, 2008 7:44 pm

Hi Richardk,
I got the solution please can you explain in details this .htaccess file, please It will better for me and other forum users.

Special this part

# Language sub domain to index.php.
RewriteCond %{HTTP_HOST} ^([a-z][a-z])\.example\.com$ [NC]
RewriteRule ^(.*)$ /index.php/%1/$1 [QSA,L]



Thanks :)

thebestmind
thebestmind
 
Posts: 7
Joined: Fri May 02, 2008 10:24 am

Postby richardk » Mon May 05, 2008 4:29 pm

Code: Select all
RewriteRule ^(index\.php|robots\.txt|favicon\.ico)$ - [L]

^ means the beginning of the URL (relative to the current directory that the .htaccess file is in)
(index\.php|robots\.txt|favicon\.ico) matches three files: index.php, robots.txt and favicon.ico.
$ matches the end of the URL.
- means "do nothing".
L means stop processing mod_rewrite.

Code: Select all
RewriteRule ^(media|css)(/.*)?$ - [L]

^ means the beginning of the URL
(media|css) matches two directories: media and css.
$ matches the end of the URL.
- means "do nothing".
L means stop processing mod_rewrite.

Code: Select all
RewriteCond %{HTTP_HOST} ^([a-z][a-z])\.example\.com$ [NC]

%{HTTP_HOST} is the (sub) domain name.
^ matches the beginning of the domain name.
([a-z][a-z]) matches two letters and puts it in %1.
\.example\.com matches ".example.com"
$ matches the end of the domain name
NC means No Case, it makes it case insensitive.

Code: Select all
RewriteRule ^(.*)$ /index.php/%1/$1 [QSA,L]

^ means the beginning of the URL (relative to the current directory that the .htaccess file is in)
(.*) matches everything and puts it in $1.
$ matches the end of the URL.
/index.php/%1/$1 is the new URL, %1 and $1 are replaced with what has been matched.
QSA means append any query string from the old URL.
L means stop.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby thebestmind » Mon May 05, 2008 10:42 pm

Great explanation every thing is clear now :).

One problem Let now out url is

http://en.site_name.com/budget/

How can I access "en"

Can I access it by $_GET[''] method. Or any other method, Because I use this variable to pass the controller.

Can you please tell me, What is the segment of "en" ?

Segment means

http://en.site_name.com/budget/make/

Here budget has 1 segment.
make has 2 segment.

Is the en has 0 segment ?

Thank you, You clear my all issue related to htaccess file.

Have good day :)
thebestmind
 
Posts: 7
Joined: Fri May 02, 2008 10:24 am

Postby richardk » Wed May 07, 2008 2:36 pm

en is in %1. You can
Code: Select all
/index.php/%1/$1?language=%1

to get
Code: Select all
$_GET['language'] = 'en'
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby thebestmind » Wed May 07, 2008 9:15 pm

Thank you, Really good forum I will refer my friends to join mod_rewrite.

Thanks Have Good Day :)
thebestmind
 
Posts: 7
Joined: Fri May 02, 2008 10:24 am

Postby thebestmind » Sat May 10, 2008 7:45 am

Hi richardk,

Sorry one more quiz, I want to force my url should start with

http://en.sitename.com/

if user place url
http://sitename.com

it should be redirect to

http://en.sitename.com/
thebestmind
 
Posts: 7
Joined: Fri May 02, 2008 10:24 am

Postby richardk » Sun May 11, 2008 1:06 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Match example.com
RewriteCond %{HTTP_HOST} ^(example\.com)$ [NC]
# Match all paths. Redirect to en.example.com with path.
RewriteRule ^(.*)$ http://en.%1/$1 [R=301,L]

RewriteRule ^(index\.php|robots\.txt|favicon\.ico)$ - [L]
RewriteRule ^(media|css)(/.*)?$ - [L]

RewriteCond %{HTTP_HOST} ^([a-z][a-z])\.example\.com$ [NC]
RewriteRule ^(.*)$ /index.php/%1/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

One more help

Postby thebestmind » Wed Aug 27, 2008 4:16 pm

Hi Friend,

Please help to solve this problem I know if easy for u.


RewriteCond %{HTTP_HOST} ^([a-z][a-z])\.example\.com$ [NC]
RewriteRule ^(.*)$ /index.php/%1/$1 [QSA,L]

This is my last rule in htaccess file. Now I want some change in url

If my url is like
http://en.example.com/member/profile/member_name
then I want to change it as below.

http://en.example.com/member_name

"member/profile" I want to hide these two word from url.

Regards,

thebestmind.
thebestmind
 
Posts: 7
Joined: Fri May 02, 2008 10:24 am

Next

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 25 guests

cron