Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to...redirect using folder structure pattern

Featured Replies

Hello

 

How do I write a script in php that will redirect to within a certain folder structure...

 

basically if I have an english site - www.example-site.com and a spanish version of the site within the subfolder www.example-site.com/spanish/ and a german in www.example-site.com/german how do I create a script that will say go to the same page but in the german site.

 

So if they are on a page in english site but an earlier script recognises they have german set as their browser language how can I make it redirect to the equivalent page in german using a pattern so the same script can be used for each page.

 

Thanks in advance for any suggestions.

I'm no expert in PHP but I think you need to do a check to identify which language they have installed, assign it to a variable and then place it in a header redirect.

  • Author

yes, just don't want to have to specify different redirect address on each page.

 

So I want a way of php detecting the page url say it's www.example-site/contact.php and then putting in the relevant subfolder within that path, i.e. www.example-site/spanish/contact.php so I could use the same code on each page. How do I get the language folder put in the path in correct order?

 

Cheers

Hello

 

How do I write a script in php that will redirect to within a certain folder structure...

 

basically if I have an english site - www.example-site.com and a spanish version of the site within the subfolder www.example-site.com/spanish/ and a german in www.example-site.com/german how do I create a script that will say go to the same page but in the german site.

 

So if they are on a page in english site but an earlier script recognises they have german set as their browser language how can I make it redirect to the equivalent page in german using a pattern so the same script can be used for each page.

 

Thanks in advance for any suggestions.

 

as mentioned do a check to see what language was installed then use a swtich statement

 

switch($lang){
case 'en':
//English redirect
break;
case 'spanish':
//Spanish redirect
break;
}

  • Author

no I've got that bit, it's just I don't want to have to put the script at the top of each page and put a different redirect in for each page.

 

for eg. on home page i'd have

 

 

switch($lang){

case 'en':

//English redirect

header ("Location: http://www.example.com");

break;

case 'spanish':

//Spanish redirect

header ("Location: http://www.example.com/spanish");

 

break;

}

 

 

whereas on contact page I'd need a different redirect... header ("Location: http://www.example..com/spanish/contact.php");

 

is there something I can write that basically says...

 

 

case 'spanish'

1. work out current url, answer www.example.com/photos-page.php

2.Recreate that url with /spanish/ in the correct place (i.e. www.example.com/spanish/photos-page.php)

 

That is what I'm trying to figure out , if that makes sense

  • 3 weeks later...

If you have a properly made site you wouldn;t be redirecting at all. Ideally, the language would be a parameter passed to your bootstrap code.

 

So site.co.uk/en/news/index would load the news controller, using the English language file. Having a dupliacted versions of the site in different folders is plain stupid in my eyes and leads to lots of duplication. For instance, say you find a bug in one of your controllers. YOu'll need to duplicate that fix ac ross however many languages you have. All creating lots of hard work for yourself.

 

Seriously, for things like internationalisation you REALLY want to invest some time in a decent framework.

 

Re pasting the code on each page, surely you have a bootstrap file used on every page?

This x1000

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.