将 URL 重定向到 .htaccess 文件中的路径

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

我想将所有内容重定向到“domain.tld/shop/...”,但它总是将index.php添加到URL“domain.tld/shop/index.php/...”

这就是我在 .htaccess 文件开头添加的内容:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/shop
    RewriteRule ^(.*)$ /shop/$1 [L,R=301]
</IfModule>

这是整个 .htaccess 文件:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/shop
    RewriteRule ^(.*)$ /shop/$1 [L,R=301]
</IfModule>

# BEGIN Shopware
# The directives (lines) between "# BEGIN Shopware" and "# END Shopware" are dynamically generated. Any changes to the directives between these markers will be overwritten.

DirectoryIndex index.php

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    # Sets the HTTP_AUTHORIZATION header removed by Apache
    RewriteCond %{HTTP:Authorization} .
    RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]

    # If the requested filename exists, simply serve it.
    # We only want to let Apache serve files and not directories.
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]

    # Rewrite all other queries to the front controller.
    RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /index.php/
    </IfModule>
</IfModule>

<IfModule mod_headers.c>
    <FilesMatch "\.(?i:svg)$">
        Header set Content-Security-Policy "script-src 'none'"
    </FilesMatch>
</IfModule>

# END Shopware

注意:我也尝试过这种条件:

RewriteCond %{REQUEST_URI} !^/shop/

我尝试将其放置在文件中的不同位置,但都不起作用。

apache .htaccess shopware shopware6
1个回答
-1
投票

要使用 .htaccess 将所有内容重定向到“domain.tld/shop/”,您可以使用以下代码。确保将“domain.tld”替换为您的实际域名:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/shop/
RewriteRule ^(.*)$ /shop/$1 [L,R=301]
© www.soinside.com 2019 - 2024. All rights reserved.