#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Posts
    6
    Rep Power
    0

    Country Code Regular Espression


    Hey,
    Iím wondering if someone can help with some Reg-Ex code development, I currently have a site which operates multiple language versions as follows
    - /en/page-url
    - /fr/page-url
    - /de/page-url
    Now all of the above donít actually load unique content so what I want to do is develop some code which will redirect all of the indivudal urls to go to the main domain so
    - /en/page-url to /page-url
    Wondering if someone can help?
    Kev
  2. #2
  3. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,383
    Rep Power
    9645
    If those were the only three languages your site supported then the expression is
    Code:
    (en|fr|de)
    I'm not sure where the problem is. If you have more languages, add them. Or is the problem the redirection?

    Though really, this sounds much easier to do in code: any page request which specifies a language should redirect to the non-language URL.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Posts
    6
    Rep Power
    0
    Hey

    I was wondering if there was a way to use one piece of reg ex to redirect each page for example /en/houses to /houses /de/houses /houses etc
  6. #4
  7. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,383
    Rep Power
    9645
    Yeah, but the problem is identifying the languages. Do you have a list of all the languages your site supports? Are there any localized pages without unlocalized/English versions, or vice versa?

    And I'll ask it again: assuming you're trying to solve a problem and think that regex is the solution, what would it take for your site's code to do the redirect instead?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Posts
    6
    Rep Power
    0
    Hey

    Yeah so I have a list of all the languages and all the pages are the same url just with the country extension before them. It would need some code adding to the .htaccess I'd guess
  10. #6
  11. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,383
    Rep Power
    9645
    Well yeah, you'll have to add something.

    Take the list, stuff them between () with |s like in the example I posted, and work that into a redirect.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Posts
    6
    Rep Power
    0
    Hey,

    Yeah was wondering if there was a way you could get the file extension to match and redirect to the none country version without multiple lines of code?
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Posts
    6
    Rep Power
    0
    I have the below but as soon as I add in multiple country sub folder the URL breaks and just re-directs the first URL to /fr

    RewriteEngine on
    RewriteRule ^fr/(.*) /$1 [L]

    I tried

    RewriteEngine on
    RewriteRule ^(de|en|fr)/(.*) /$1 [L]
  16. #9
  17. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,383
    Rep Power
    9645
    File extension? What does that have to do with anything? Aren't you trying to redirect all localized URLs?

    $1 is the first parenthesized expression. Take a second to think about that.

IMN logo majestic logo threadwatch logo seochat tools logo