【问题标题】:Apache prepend URL before requested URLApache 在请求的 URL 之前添加 URL
【发布时间】:2017-05-29 09:43:23
【问题描述】:

如何检索这样的 URL:

http://xxx.example.com/resource/blahblah

并重写这个地址

http://example.com/yyy/zzz/vvv.html?subject=http://xxx.example.com/resource/blahblah

通过 Apache 服务器并使用 mod-rewrite。

【问题讨论】:

    标签: apache mod-rewrite url-rewriting


    【解决方案1】:

    保存url的内容。然后将index.html页面上传到apache服务器,启动apache服务器。

    【讨论】:

    • 我想使用mod-rewrite,我无法将我所有的6000000个url都保存在html文件中!
    • mod_rewrite 用于重写 URL。例如 www.xyz.com/login/sahil 被转换为 www.xyz.com/login.html?name=sahil
    【解决方案2】:

    我不知道为什么这个问题有负面意义!而且我不知道为什么答案如此无关紧要。反正我自己找到了真正的答案。

    在此路径中创建一个文件或编辑该文件:

    sudo nano /var/www/html/.htaccess
    

    填写文件:

    RewriteEngine On
    
    # avoids recursive rewrite of scripts
    RewriteCond %{HTTP_REFERER}  ^http://xxx\.example\.com/.*$
    RewriteRule ^yyy/.* - [L]
    
    # rewrites scripts and css files
    RewriteCond %{HTTP_REFERER}  ^http://xxx\.example\.com/.*$
    RewriteRule ^(.*)$ yyy/$1 [QSA]
    
    RewriteRule ^resource/([^\/]*)$ yyy/zzz/vvv.html?subject=http://xxx.example.com/resource/$1 [QSA]
    

    并重启apache服务:

    sudo service apache2 restart
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-07
      • 2016-11-22
      • 2022-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      相关资源
      最近更新 更多