.htaccess 语言路径 /en/

问题描述 投票:0回答:1

我的 .htaccess 有问题 在本地主机上,它在语言上停止并重定向到控制器:

http://spa.domain.loc/en/about-us.html

如果我尝试在线实时服务器,我会收到 404,因为未在语言条件下输入

https://spa.domain.ro/en/rezervare-spa.html

我尝试在路径后添加语言,如下所示:/en/,但要获得正确的控制器 php 我需要这样的东西https://spa.domain.ro/rezervare-spa.html?lang=en 我想知道 php 中的 lang 参数,但用户看不到它

    RewriteEngine On

# REWRITE IF HAVE LANGUAGE /en/ path
    RewriteBase /

    # Force trailing slash on language code
    RewriteRule ^(en)$ $1/ [R=301,L]

    # Default to Romanian (other languages example path. /en/<anything>)
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} ^/(.*)
    #RewriteRule !^(en/|/)(.*) %1 [R,L]

    # Route language URLs
    RewriteRule ^([a-zA-Z]{2})/(.*) $2?lang=$1 [QSA,L]

# END LANGUAGE

    # Security Fixes
    RewriteRule ^\.htaccess$ - [F,L]
    RewriteRule ^_scripts/ - [F,L]
    RewriteRule ^_sql/ - [F,L]
    RewriteRule ^_logos/ - [F,L]
    RewriteRule ^etc/live\.2CQA\-VZRG\-6AVL\-PB0Q\-1KJP\.public\.cer$ - [F,L]
    RewriteRule ^etc/live\.2CQA\-VZRG\-6AVL\-PB0Q\-1KJPprivate\.key$ - [F,L]
    RewriteRule ^etc/config\.php$ - [F,L]
    RewriteRule ^etc/config-index\.php$ - [F,L]
    RewriteRule ^etc/config-admin\.php$ - [F,L]
    RewriteRule ^etc/init\.php$ - [F,L]
    RewriteRule ^etc_online/config\.php$ - [F,L]
    RewriteRule ^etc_online/config-index\.php$ - [F,L]
    RewriteRule ^etc_online/config-admin\.php$ - [F,L]
    RewriteRule ^etc_online/init\.php$ - [F,L]
    RewriteRule ^tmp/ - [F,L]
    RewriteRule ^wpub/\.htaccess$ - [F,L]
    RewriteRule ^wpub/\#wpub$ - [F,L]
    RewriteRule ^\#db/ - [F,L]



    ##### Temporary maintenance ; must be 302 as 307 does not behave correctly (if the file maintenance.html exists in the web root)

    RewriteCond %{HTTP_HOST} ^(.*)\.
    RewriteCond /maintenance.html !-f
    RewriteRule ^maintenance.html$ / [L,R=301]

    RewriteCond %{HTTPS}            off
    RewriteCond %{HTTP_HOST}        ^(?:(spa)\.)?(domain\.ro)$

    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


    # Redirect to www if no sub-domain (Ex: http(s)://domain.ext -> http(s)://www.domain.ext)
    RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
    RewriteCond %{HTTPS}s ^on(s)|
    RewriteRule ^ http%1://spa.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Homepage Rules
    #RewriteCond        %{HTTP_HOST} ^(www)\.
    RewriteRule         ^$   index.php?page=frontend.homepage [QSA,L]

    # Custom Rules: old-rules
    RedirectMatch 301 ^/about\.html$                                /about-us.html
    RedirectMatch 301 ^/rates\.php$                                 /rates.html
    RedirectMatch 301 ^/news\.php$                                  /news.html
    RedirectMatch 301 ^/location\.php$                              /location.html
    RedirectMatch 301 ^/gallery\.php$                               /gallery.html
    RedirectMatch 301 ^/privacy-policy\.php$                        /privacy-policy.html
    RedirectMatch 301 ^/contact\.php$                               /contact.html


    # RULES MOBILPAY PAYMENT
        # Custom Rules: return-mobilpay
        RewriteCond         %{REQUEST_FILENAME} !-f
        RewriteCond         %{REQUEST_FILENAME} !-d
        RewriteRule         ^return-mobilpay\.html$                                         index.php?page=frontend.mobilpay-return [QSA,L]

        # Custom Rules: confirm-mobilpay
        RewriteCond         %{REQUEST_FILENAME} !-f
        RewriteCond         %{REQUEST_FILENAME} !-d
        RewriteRule         ^confirm-mobilpay\.html$                                        index.php?page=frontend.mobilpay-confirm [QSA,L]

    # RULES VIVA WALLET PAYMENT
        # Custom Rules: return-vivawallet
        RewriteCond         %{REQUEST_FILENAME} !-f
        RewriteCond         %{REQUEST_FILENAME} !-d
        RewriteRule         ^return-vivawallet\.html$                                       index.php?page=frontend.vivawallet-return [QSA,L]

        # Custom Rules: confirm-vivawallet
        RewriteCond         %{REQUEST_FILENAME} !-f
        RewriteCond         %{REQUEST_FILENAME} !-d
        RewriteRule         ^confirm-vivawallet\.html$                                      index.php?page=frontend.vivawallet-confirm [QSA,L]



    # Custom Rules:
    #RewriteCond        %{REQUEST_FILENAME} !-f
    #RewriteCond        %{REQUEST_FILENAME} !-d
    #RewriteRule        ^rezervare-bungalow\.html$                                      index.php?page=frontend.rezervare-camera&roomid=3 [QSA,L]

    # Custom Rules:
    RewriteCond         %{REQUEST_FILENAME} !-f
    RewriteCond         %{REQUEST_FILENAME} !-d
    RewriteRule         ^offers\.html$                                                  index.php?page=frontend.offers-view [QSA,L]

    ### Sitemap XML Index
    RewriteCond         %{REQUEST_FILENAME} !-f
    RewriteCond         %{REQUEST_FILENAME} !-d
    RewriteRule         ^sitemap\.xml$                                                  /index.php?page=frontend.sitemap-sdom-idx [QSA,L]
    ### Sitemap XML Content
    RewriteCond         %{REQUEST_FILENAME} !-f
    RewriteCond         %{REQUEST_FILENAME} !-d
    RewriteRule         ^sitemap-content\.xml$                                          /index.php?page=frontend.sitemap-sdom-content [QSA,L]
    ###
    # Custom Rules: backend
    RewriteCond         %{REQUEST_FILENAME} !-f
    RewriteCond         %{REQUEST_FILENAME} !-d
    RewriteRule         ^backend.(.*)\.html$                                        admin.php?page=backend\-new.$1 [QSA,L]

    # General rewrite rules: map controller name to something else
    RewriteCond         %{REQUEST_FILENAME} !-f
    RewriteCond         %{REQUEST_FILENAME} !-d
    RewriteRule         ^(.*)\.(html|stml|json|xml|rss|csv|txt|png|gif|jpg|pdf|webp)$       index.php?page=$1 [QSA,L]

    ErrorDocument 400 /index.php?page=frontend.400
    ErrorDocument 404 /index.php?page=frontend.404

我测试了 htaccess,据说它很好......但是在我的本地主机上工作正常,而在实时服务器上不工作...... https://htaccess.madewithlove.com?share=57608579-efb9-409b-b092-b1936d9ca4a6

php apache .htaccess mod-rewrite
1个回答
0
投票

我发现了问题,托管实时服务器使用 LiteSpeed Apache,并且有很多 [L] 条件,因此,这个特定标志以不同的方式工作。网址:https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:故障排除:rewrite_difference_on_l_flag_ Between_lsws_and_apache

新的 .htaccess 看起来像这样:

# REWRITE IF HAVE LANGUAGE /en/ path
RewriteBase /

# Force trailing slash on language code
RewriteRule ^(en)$ $1/ [R=301]

# Default to Romanian (other languages example path. /en/<anything>)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/(.*)
#RewriteRule !^(en/|/)(.*) %1 [R,L]

# Route language URLs
RewriteRule ^([a-zA-Z]{2})/(.*) $2?lang=$1 [QSA]
© www.soinside.com 2019 - 2024. All rights reserved.