首页 > 解决方案 > Silverstripe 4.7.3 htaccess 重定向问题

问题描述

也许有人在这里使用 silverstripe 4.7.3 可以帮助我。

我对一种解决方案有疑问。我需要在不同的 URL 地址显示某个页面,例如:

test?code=1234 我使用 get 的代码从 db 下载一些记录,这个页面是在 cms 中创建的,到这个页面的链接是 /test。这个页面工作。

但现在我想在另一个 URL 上显示这个页面,应该是这样的:/test-1234/

RewriteRule ^test-(\d{4})/(([\sąćęłńóśźżĄĆĘŁŃÓŚŹŻa-zA-Z0-9_-])*)(\/)? /test/?code=$1&code=$2&%{QUERY_STRING} [L]

我发现 htaccess 中的这条规则没有得到满足,但我检查了标志 R=301 并且这条规则有效,有人可以解释为什么没有 R=301 的规则只有 [L] 不适用于原始 htaccess 吗?我包括完整的文件

<Files web.config>
    Require all denied
</Files>

# Deny access to YAML configuration files which might include sensitive information
<Files ~ "\.ya?ml$">
    Require all denied
</Files>

# Route errors to static pages automatically generated by SilverStripe
ErrorDocument 404 /assets/error-404.html
ErrorDocument 500 /assets/error-500.html
#ErrorDocument 503 /assets/error-503.html

<IfModule mod_rewrite.c>

    # Turn off index.php handling requests to the homepage fixes issue in apache >=2.4
    <IfModule mod_dir.c>
        DirectoryIndex disabled
        DirectorySlash On
    </IfModule>


    SetEnv HTTP_MOD_REWRITE On
    RewriteEngine On

    RewriteRule ^test-(\d{4})/(([\sąćęłńóśźżĄĆĘŁŃÓŚŹŻa-zA-Z0-9_-])*)(\/)? /test/?code=$1&code=$2&%{QUERY_STRING} [L]

    # Process through SilverStripe if no file with the requested name exists.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* index.php

    # Enable HTTP Basic authentication workaround for PHP running in CGI mode
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Deny access to potentially sensitive files and folders
    RewriteRule ^vendor(/|$) - [F,L,NC]
    RewriteRule ^\.env - [F,L,NC]
    RewriteRule silverstripe-cache(/|$) - [F,L,NC]
    RewriteRule composer\.(json|lock) - [F,L,NC]
    RewriteRule (error|silverstripe|debug)\.log - [F,L,NC]

</IfModule>
### SILVERSTRIPE END ### ```



标签: regexapache.htaccesssilverstripe

解决方案


推荐阅读