简体   繁体   中英

Codeigniter internationalization redirect index.php

I'm using Codeigniter and I did the internationalization using : CI-internationalization

I would like to add /en by default when the user access my site :

www.mysite.com -> www.mysite.com/en

What is the best way to achieve that ?

Thank you.

HTML redirects

The simplest way to redirect to another URL is with the Meta Refresh tag. You can place this meta tag inside the <head> at the top of any HTML page like this:

<meta http-equiv="refresh" content="0; URL='http://www.new-site.com/en'" />

The content attribute is the delay before the browser redirects to the new page, above example it is set to 0 seconds.

JavaScript redirects

Redirecting to another URL with JavaScript is pretty easy, we simply have to change the location property on the window object:

window.location = "http://www.new-site.com/en";

OR

window.location.href = "http://www.new-site.com/en";

OR

window.location.assign("http://www.new-site.com/en");

OR

window.location.replace("http://www.new-site.com/en");

PHP redirects

<?php
  header('Location: http://www.new-site.com/en', true, 301);
  exit();
?>

This has to be set before any markup or content of any other sort, however there is one small hitch. By default the function sends a 302 redirect response which tells everyone that the content has only been moved temporarily. Considering our specific use case we'll need to permanently move the files over to our new website, so we'll have to make a 301 redirect instead. The optional true parameter above will replace a previously set header and the 301 at the end is what changes the response code to the right one

Source: https://css-tricks.com/redirect-web-page/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>
    Testing page
</title>
<meta http-equiv="refresh" content="0; URL='new/test.html'" />
</head>
<body>
   Old page 
</body>
</html>

second/new page

<html>
<head>
<title>new site
</title>
</head>
<body>
this is new page.
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM