RewriteRule将example.com/12345重定向到https://example.com/index.html?id=12345

时间:2019-02-17 17:09:06

标签: ubuntu url-rewriting url-redirection

我正在尝试为用户创建一种将URL键入为example.com/12345并将其重写为https://www.example.com/index.html?id=12345的方法。 “ id”参数至少应为6位数,并且不能为最大值。我似乎无法获得第一个RewriteRule才能正常工作。当用户键入www.example.com/12345之类的网址时,它将重定向到https://www./12345

第二个RewriteRule将所有其他流量重定向到https://www.example.com,而不会出现问题。

<VirtualHost *:80>
    <Directory /var/www/vhosts/example/public>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ServerAdmin admin@example.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/vhosts/example/public
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    RewriteEngine On
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    RewriteRule ^([0-9]{6,})$ https://www.example.com/index.html?id=$1 
        [QSA,L,R=301,NE]
    RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
</VirtualHost>

0 个答案:

没有答案