【问题标题】:How can I rewrite this kind of URL with htaccess如何用 htaccess 重写这种 URL
【发布时间】:2013-11-18 19:11:17
【问题描述】:

我怎样才能用 htaccess 重写这种 url .. 下面的例子是这些虚拟 url

更新 .htaccess,这样当有人访问 http://cheapbats.mediagroup.com/19 时,它会将他们重定向到 http://cheapbats.cmediagroup.com/index.php?ref=19

The rule is, if not a directory or file,是一个数字,然后重定向到index.php? ref=[数字]

【问题讨论】:

    标签: php regex apache .htaccess mod-rewrite


    【解决方案1】:

    您可以在DOCUMENT_ROOT/.htaccess 文件中尝试此规则:

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([0-9]+)/?$ /index.php?ref=$1 [L,QSA]
    

    【讨论】:

    • 你能详细说明什么不起作用。请记住,这是一个静默(内部)重写,因此它不会更改浏览器中的 URL。
    • 谢谢...你能推荐我在哪里学习htaccess的用法吗?
    • 这是官方文档:httpd.apache.org/docs/current/rewrite/intro.html 但大多数情况下它会通过实践和答案来实现
    • 感谢您的回复。
    • ..你认为你能帮我解决这个问题吗..没有人回答它..stackoverflow.com/questions/20052818/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-28
    • 2020-04-09
    • 2011-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多