2

我在 WOULD NOT WORK 区域中的 mod 重写规则有问题 :) 我有一个项目站点,女巫只是一个 ajax 返回站点。所以我喜欢在 sitename.com/my-test/project/test.html 上打开我的网站,并且会重写 sitename.com/my-test/project.html?index=test。我知道在我重写之后,cms 的重写规则必须完成他的工作。我不确定这可能是问题所在,他们交叉或崩溃。

如果我通过浏览器浏览 URL,一切都会正常工作,只有重写规则不起作用,我变得非常疯狂,找不到问题。

所以我希望有人能帮助我。

在 .htaccess 中重写配置

    RewriteEngine On
    RewriteBase /

    #### WOULD NOT WORK ######
    # REWRITE AJAX PROJEKT
    RewriteCond %{REQUEST_URI}% ^my-test/projects/[a-zA-Z0-9]+\.html$ [NC]
    RewriteRule ^my-test/projects/[a-zA-Z0-9]+\.html my-test/projects.html?index=$1

    ### WORK CORRECTLY ####
    # REWRITE RULE FOR SEO FRIENDLY IMAGE MANAGER URLS
    RewriteRule ^files[0-9]*/imagetypes/([^/]*)/([^/]*) index.php?rex_img_type=$1&rex_img_file=$2

    # DON'T REWRITE IF REAL FILE, FOLDER OR SYMLINK EXISTS
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l

    # EXCLUDE SPECIFIC FOLDERS FROM REWRITE ENGINE
    RewriteCond %{REQUEST_URI} !/files[0-9]*/
    RewriteCond %{REQUEST_URI} !/assets/.*
    RewriteCond %{REQUEST_URI} !/media/.*
    RewriteCond %{REQUEST_URI} !/redaxo/.*

    # REWRITE ALL OTHER REQUESTS TO INDEX.PHP
    RewriteRule ^(.*)$ index.php?%{QUERY_STRING} [L]

我也测试过

    RewriteCond %{REQUEST_URI}% ^/my-test/projects/[a-zA-Z0-9]+\.html$ [NC]
    RewriteRule ^/my-test/projects/[a-zA-Z0-9]+\.html my-test/projects.html?index=$1
    #OR JUST
    RewriteRule ^/my-test/projects/[a-zA-Z0-9]+\.html$ my-test/projects.html?index=$1
    #OR
    RewriteRule ^/my-test/projects/(.*)$ my-test/projects.html?index=$1
    #AND CORRECT
    RewriteCond %{REQUEST_URI} ^/my-test/projects/[a-zA-Z0-9]+\.html$ [NC]
    RewriteRule ^/my-test/projects/[a-zA-Z0-9]+\.html my-test/projects.html?index=$1
    #AND ---
    RewriteRule ^my-test/projects/([a-zA-Z0-9]+)\.html my-test/projects.html?index=$1 [L]
    

我没有找到答案,所以我真的希望有人可以帮助我

谢谢你们

吴莫克斯

4

1 回答 1

0
RewriteCond %{REQUEST_URI}% ^my-test/projects/[a-zA-Z0-9]+\.html$ [NC]
RewriteRule ^my-test/projects/[a-zA-Z0-9]+\.html my-test/projects.html?index=$1

%在你的条件结束时你有一个额外的: %{REQUEST_URI}%。这意味着它必须是请求 URI 后跟 a %,并且您在右侧的文本以 结尾html,这意味着此条件将始终失败。

此外,%{REQUEST_URI}变量/. 请注意,当用于匹配重写规则中的模式时,前导斜杠消失了。

你实际上根本不需要这个条件。

RewriteRule ^my-test/projects/([a-zA-Z0-9]+)\.html my-test/projects.html?index=$1 [L]
于 2013-09-04T21:36:07.990 回答