【问题标题】:PHP WAMP .HTACCESS How to rewrite URL?PHP WAMP .HTACCESS 如何重写 URL?
【发布时间】:2014-01-14 14:08:46
【问题描述】:

我有以下网址: http://www.domain.com/content/index.php?filename=download-file.zip&visitorid=abcd&visitorval=xyz

我想使用以下 URL 访问此脚本: http://www.domain.com/content/download-file.zip?visitorid=abcd&visitorval=xyz

我已经启用了 rewrite_module modules/mod_rewrite.so 并且我在上面的“content”子目录中添加了一个“.htaccess”文件,但是无法在 .htaccess 文件中编写规则来获取上面的内容重定向工作。

想法?

【问题讨论】:

    标签: php apache .htaccess mod-rewrite redirect


    【解决方案1】:

    将此代码放入您的 /content/.htaccess 文件

    RewriteEngine On
    RewriteBase /sites/some.domain.com/content/
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ index.php?filename=$1 [L,QSA]
    

    【讨论】:

    • 非常感谢您的超快速响应:) 我试过这个,它给了我与我不同的结果,但它没有用。让我添加更多详细信息:我的完整 URL 是:localhost/sites/some.domain.com/content/… 我想将其用作:localhost/sites/some.domain.com/content/… 当我使用上面的代码时,它会将我重定向到localhost/index.php
    • 注意:我还想支持不同的文件扩展名 [zip, rar, doc etc...]
    • 好的,您应该在问题本身中提供这些详细信息以获得更好的答案。让我编辑我的答案。
    • 谢谢!!!!这在我的本地主机上效果很好。我们可以让它更动态吗,因为当我们发布它来直播时,URL 会像:some.domain.com/content/…some.domain.com/content/… 其中“some.domain.com”值也是动态的[我们有几个动态生成的域]
    • 好的,你可以尝试注释掉RewriteBase这一行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-03
    • 1970-01-01
    • 2018-05-31
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多