【问题标题】:Htaccess rewrite to certain page/languageHtaccess 重写到某些页面/语言
【发布时间】:2014-06-18 19:24:41
【问题描述】:

我试图让重定向监听某个域。 我有 3 个域; - www.tocdesal.com

  • www.tocdesal.es

  • www.tocdesal.nl

现在我想实现这个..

www.tocdesal.com > www.tocdesal.com/en_GB/

www.tocdesal.nl > www.tocdesal.com/nl_NL/

www.tocdesal.es > www.tocdesal.com/es_ES/

这是我用来管理多语言和禁止人们进入某些文件夹的一些代码。 我希望有人可以帮助我使用此功能。

<IfModule mod_rewrite.c>
    # Turn on URL rewriting
    RewriteEngine On

    # NON-WWW > WWW
    #RewriteCond %{HTTP_HOST} ^www\.tocdesal\.nl [NC]
    #RewriteRule (.*) http://www.tocdesal.nl/nl_NL/home/$1 [R=301,L]

    # CUSTOM REWRITES
    #Redirect 301 /[oldlink] [new-full-link]

    # We dont want snooping people
    Options -Indexes

    #RewriteCond %{REQUEST_URI} ^framework.*

    # If your website begins from a folder e.g localhost/my_project then 
    # you have to change it to: RewriteBase /my_project/
    # If your site begins from the root e.g. example.local/ then
    # let it as it is
    #RewriteBase /tvmoordrecht

    # Protect application and system files from being viewed when the index.php is missing
    RewriteCond $1 ^(framework/modules|framework/coremodules|framework/cicore|application|assets|custommodules)

    # Rewrite to index.php/access_denied/URL
    RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]

    # Allow these directories and files to be displayed directly:
    RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|css|js|images|img|fonts|upload|framework/assets/|themes|framework/apps/elfinder|dev-cmslemonupdater|cmslemonupdater)

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

    # Rewrite to index.php/URL
    RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>

【问题讨论】:

    标签: regex apache .htaccess codeigniter mod-rewrite


    【解决方案1】:

    RewriteEngine On 行之后插入这 3 条规则:

    RewriteCond %{HTTP_HOST} ^(?:www\.)?tocdesal\.com$ [NC]
    RewriteRule !^en_GB/ http://www.tocdesal.com/en_GB%{REQUEST_URI} [NE,R=301,L,NC]
    
    RewriteCond %{HTTP_HOST} ^(?:www\.)?tocdesal\.nl$ [NC]
    RewriteRule ^ http://www.tocdesal.com/nl_NL%{REQUEST_URI} [NE,R=301,L]
    
    RewriteCond %{HTTP_HOST} ^(?:www\.)?tocdesal\.es$ [NC]
    RewriteRule ^ http://www.tocdesal.com/es_ES%{REQUEST_URI} [NE,R=301,L]
    

    【讨论】:

    • 遗憾的是它没有用。我仍然得到了无尽的重定向循环。我认为它可能是导致问题的其他行的问题。我在 .htaccess 中没有那种天赋
    • 你会循环哪个 URL?
    • .es 现在可以使用了!伟大的!还有一种方法可以让所有域的非 www 分别转到 www.tocdesal。* 如果可以做到,我非常非常高兴
    • 谢谢@anubhava,该解决方案仅在我将 .com 重写放入 .com 翻转并再次跳闸和循环时才有效。我还将规则按 3 次重写的顺序放在最后,但它没有帮助。它与 .com 域一起使用并不是很重要,它是标准的英文版。
    • 我在第一条规则中做了一个更正以防止循环。
    【解决方案2】:

    这就是我现在所拥有的。非 www 重定向到标准域 (.com) 的 www,其余重定向到域设置的语言。

    <IfModule mod_rewrite.c>
        # Turn on URL rewriting
        RewriteEngine On
    
        # Redirects to the page with that language selected
    
        RewriteCond %{HTTP_HOST} !^www\.
        RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    
        RewriteCond %{HTTP_HOST} ^(?:www\.)?tocdesal\.nl$ [NC]
        RewriteRule ^ http://www.tocdesal.com/nl_NL%{REQUEST_URI} [NE,R=301,L]
    
        RewriteCond %{HTTP_HOST} ^(?:www\.)?tocdesal\.es$ [NC]
        RewriteRule ^ http://www.tocdesal.com/es_ES%{REQUEST_URI} [NE,R=301,L]
    
        # CUSTOM REWRITES
        #Redirect 301 /[oldlink] [new-full-link]
    
        # We dont want snooping people
        Options -Indexes
    
        #RewriteCond %{REQUEST_URI} ^framework.*
    
        # If your website begins from a folder e.g localhost/my_project then
        # you have to change it to: RewriteBase /my_project/
        # If your site begins from the root e.g. example.local/ then
        # let it as it is
        #RewriteBase /tvmoordrecht
    
        # Protect application and system files from being viewed when the index.php is mi
        RewriteCond $1 ^(framework/modules|framework/coremodules|framework/cicore|applica
    
        # Rewrite to index.php/access_denied/URL
        RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
    
        # Allow these directories and files to be displayed directly:
        RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|css|js|images|img|fonts|uplo
    
        # No rewriting
        RewriteRule ^(.*)$ - [PT,L]
    
        # Rewrite to index.php/URL
        RewriteRule ^(.*)$ index.php/$1 [PT,L]
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-22
      • 2016-11-04
      • 2012-03-20
      • 2012-11-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多