【问题标题】:trying to rewrite url in htaccess试图在 htaccess 中重写 url
【发布时间】:2012-08-28 13:37:48
【问题描述】:

我有网址

http://www.url.com/business/index.php?biz=andrewliu

我正在努力完成,所以它会是

http://www.url.com/business/andrewliu

我尝试过这个:

RewriteRule ^/?([a-z0-9_-]+)/?$ /index.php?biz=$1 [L]

RewriteRule ^/?([a-z0-9_-]+)/?$ /business/index.php?biz=$1 [L]

没有用?

帮帮我?

编辑:

我有这个

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 

重写之前

【问题讨论】:

    标签: .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    这取决于您的.htaccess 文件在哪个目录中。

    对于根目录试试这个:

    RewriteRule ^/?business/([a-zA-Z0-9_-\.]+)/?$ /business/index.php?biz=$1 [L]
    

    如果您的.htaccess 文件在业务目录中,那么您的语句应该可以正常工作:

    RewriteRule ^/?([a-zA-Z0-9_-\.]+)/?$ /index.php?biz=$1 [L]
    

    【讨论】:

    • htaccess 在根目录下。但是,它似乎无法正常工作。
    • 我可以拥有多个 htaccess 文件吗?我应该在每个目录中放置一个吗?
    • 您是否已使用RewriteEngine on 行激活ModRewrite?可以使用多个.htaccess 文件,但您应该知道最高级的文件具有最高优先级。
    • 用户名有可能有大写字母吗?您还可以尝试删除重定向到的脚本文件开头的斜杠。
    • 我想通了。我最初有一个 .com 或其他东西作为我的用户名,但我想我不能拥有它
    【解决方案2】:

    重写规则 ^business/([_0-9a-zA-Z-]+)/?$ business/index.php?b=$1 [L]

    【讨论】:

      【解决方案3】:

      从您的示例中不清楚您想要“biz”、“business”还是“b”。我猜你想要“biz”,在这种情况下你的规则应该是:

      RewriteRule business/(.*) /index.php?biz=$1 [L]
      

      或者你可能想要:

      RewriteRule ([^\/]*)/(.*) /index.php?$1=$2 [L]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-04-07
        • 1970-01-01
        • 1970-01-01
        • 2020-05-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-21
        相关资源
        最近更新 更多