Welcome Guest, Not a member yet? Register   Sign In
URL Rewriting
#1

[eluser]applegh[/eluser]
Hi everybody,

I recently implemented multi language on my website and am trying now to have nice and clean urls but without success...

I have two variables to select the page displayed and the language of the page, so i can access my pages through urls like:

Code:
http://www.apple-guesthouse-sihanoukville.com/index.php/pages/view/en/home

But I would like to have urls like ***.com/en/home

I tried the following .htaccess file:

Code:
DirectoryIndex index.php
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.apple-guesthouse-sihanoukville\.com [NC]
RewriteRule (.*) http://www.apple-guesthouse-sihanoukville.com/$1 [QSA,R=301]

RedirectMatch permanent ^/$ http://www.apple-guesthouse-sihanoukville.com/en/home

RewriteCond $1 !^(index\.php|images|js|css|robots\.txt|sitemap\.xml|css|js|img|site)
RewriteRule ^([a-z]{2})\/(.*)$ index.php/pages/view/$1/$2 [R]

This file is working but i want to keep my clean url (and not use a external redirection), but when i switch the [R] flag to [L] (or [P] or nothing) i get a 404 error.

Here is a few extracts from my other files:

Controller/pages.php

Code:
$this->load->helper('url');
require("decide-lang.php");
include('application/views/templates/header.php');
include('application/views/templates/top.php');
include("application/views/pages/$page.php");
include('application/views/templates/footer.php');

Config/routes.php

Code:
$route['default_controller'] = '/pages/view';

Any idea how to fix my htaccess? Can i just remove the "index.php/pages/view" from my urls with CodeIgniter or do I absolutely have to use the .htaccess?

Thanks for your help!
#2

[eluser]weboap[/eluser]
index.php : i can understand why its there in the url
read this to take it off

http://ellislab.com/forums/viewthread/217541/


but this part : "/pages/view/" how come?

what is your file structure?


and this ??

Code:
require("decide-lang.php");
include('application/views/templates/header.php');
include('application/views/templates/top.php');
include("application/views/pages/$page.php");
include('application/views/templates/footer.php');



#3

[eluser]applegh[/eluser]
Thanks i changed my htaccess as described in your post:

Code:
DirectoryIndex index.php
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.apple-guesthouse-sihanoukville\.com [NC]
RewriteRule (.*) http://www.apple-guesthouse-sihanoukville.com/$1 [QSA,R=301]

RedirectMatch permanent ^/$ http://www.apple-guesthouse-sihanoukville.com/en/home

RewriteRule ^$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ index.php?/$1 [L]

And change my route.php

Code:
$route['default_controller'] = '/pages/view';
$route['(:any)'] = 'pages/view/$1';

And it works! Thanks a lot
#4

[eluser]applegh[/eluser]
Just one more thing.

I access my pages through urls like

www.monsite.com/en/home or
www.monsite.com/fr/room

I want to access my pages through:

en.monsite.com/home
fr.monsite.com/rooms

My htaccess was:

Code:
DirectoryIndex index.php
RewriteEngine on
RewriteBase /

RedirectMatch permanent ^/$ http://www.apple-guesthouse-sihanoukville.com/en/home

RewriteCond $1 !^(index\.php|images|js|css|robots\.txt|sitemap\.xml|css|js|img|site)
RewriteRule ^(.*)$ /index.php/$1 [L]

I tried sevral things but cannot manage to make it work... Any idea?




Theme © iAndrew 2016 - Forum software by © MyBB