【问题标题】:Replace Ugly URLs To Pretty And SEO-Friendly将丑陋的 URL 替换为漂亮且对 SEO 友好
【发布时间】:2013-11-07 17:12:20
【问题描述】:

我正在寻找一个 .htaccess 重写 URL 解决方案来将我的 Web 应用程序的丑陋 URL 转换为 Pretty one。之前我已经使用以下 .htaccess 代码将 URL localhost/example/user.php?u=username 转换为 localhost/example/username

RewriteRule ^([^/\.]+)/?$ user.php?u=$1

现在我想转换以下网址:

localhost/example/messages.php?u=username ----> localhost/example/messages

谢谢。

【问题讨论】:

    标签: .htaccess url mod-rewrite rewrite


    【解决方案1】:

    将这两条规则保存在您的 DOCUMENT_ROOT/.htaccess 文件中:

    RewriteEngine On
    
    RewriteRule ^([^/.]+)/?$ user.php?u=$1 [L,QSA]
    
    RewriteRule ^([^/]+)/([^/.]+)/?$ /$1/user.php?u=$2 [L,QSA]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-09
      • 2011-12-27
      • 2016-04-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多