【问题标题】:Apache URL Rewrite query stringApache URL 重写查询字符串
【发布时间】:2019-02-13 23:06:14
【问题描述】:

我想重写这个网址:

https://example.com/super/index.php?route=doo/math&user_token=AxDJFKDLS73jfd

进入这个网址:

https://example.com/super/math&user_token=AxDJFKDLS73jfd

甚至是这个:

https://example.com/super/user_token=AxDJFKDLS73jfd

我尝试了不同的方法,通过修改 /super 目录中的 .htaccess 并添加:

RewriteEngine On
RewriteRule ^super/$ index.php?route=doo/math [L]

也试过了:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^route=doo/math([^&]+)&?(.*)$
RewriteRule ^/?$ /%1?%2 [R,L]

也可以直接在 apache vhost 中添加:

<IfModule mod_rewrite.c>
    RewriteCond %{QUERY_STRING} ^(.*)&route=([0-9]{10,12})(?:&)(.*)$
    RewriteRule ^(.*)$ https://%{SERVER_NAME}/super/$1?%1/%2\?%3 [NE,L,R]
</IfModule>

很遗憾,这些方法都不起作用,非常感谢您的帮助。

【问题讨论】:

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


    【解决方案1】:

    这应该有效并适用于https://example.com/super/user_token=AxDJFKDLS73jfd

    RewriteEngine on
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
    RewriteRule ^super/user_token\=(.*)$ /index.php?route=doo/math&user_token=$1 [L]
    

    编辑:

    或者你甚至可以使用它

    RewriteRule ^super/user_token\=([a-zA-Z0-9_-]+)$ /index.php?route=doo/math&user_token=$1 [L]
    

    符合您的条件。 A-Z-0-9

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-27
      • 2021-01-06
      • 2011-08-02
      • 2012-01-18
      • 1970-01-01
      • 2020-01-25
      相关资源
      最近更新 更多