【问题标题】:How to rewrite url in php can anyone help please?如何在 php 中重写 url 任何人都可以帮忙吗?
【发布时间】:2015-05-09 08:06:19
【问题描述】:

任何人都可以帮助我,我想重写网址

http://www.fvilla.in/single.php?username='ankit12541'

http://fvilla.in/ankit12541

【问题讨论】:

  • 用 PHP 重写 URL?为什么?只需使用“新”网址,一切都很好。这里的问题是什么?我假设您想通过在 .htaccess 样式文件中指定规则来在 http 服务器重写模块中进行重写。但在那种情况下,您的问题中显示的重写方向没有意义......
  • 最好使用示例域作为示例。见:en.wikipedia.org/wiki/Example.com

标签: .htaccess url-rewriting


【解决方案1】:

我相信您的意思是使用 .htaccess 文件重写 URL。您的文件应如下所示:

Options -Indexes
Options +FollowSymLinks
<IfModule mod_rewrite.c>
 RewriteEngine On

 RewriteCond %{HTTP_HOST} ^fvilla.in$ [NC]
 RewriteRule ^/([^/]+)$ /single.php?username=$1
</IfModule>

这可行,但实际上没有意义,因为它会重写您域中的任何 URL。

这样会更好

http://www.fvilla.in/single.php?username='ankit12541'
 to
http://fvilla.in/user/ankit12541

像这样使用 .htaccess 文件:

Options -Indexes
Options +FollowSymLinks
<IfModule mod_rewrite.c>
 RewriteEngine On

 RewriteCond %{HTTP_HOST} ^fvilla.in$ [NC]
 RewriteRule ^/user/([^/]+)$ /single.php?username=$1
</IfModule>

【讨论】:

    猜你喜欢
    • 2011-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-31
    • 2010-10-10
    • 2023-04-07
    • 1970-01-01
    相关资源
    最近更新 更多