apache mod_rewrite - 重写规则

时间:2013-09-04 20:52:10

标签: apache .htaccess mod-rewrite url-rewriting

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

如果我通过浏览器浏览网址,一切都会正常工作,只有重写规则不起作用,我变得完全疯了,无法找到问题。

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

.htaccess中的REWRITE CONFIG

    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]

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

谢谢大家

纳克 moxx

1 个答案:

答案 0 :(得分: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,并且您在右侧以html发送文本,这意味着此条件将始终失败。

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

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

RewriteRule ^my-test/projects/([a-zA-Z0-9]+)\.html my-test/projects.html?index=$1 [L]