【问题标题】:.htaccess rewrite pretty url.htaccess 重写漂亮的 url
【发布时间】:2016-01-25 01:43:54
【问题描述】:

我是 .htaccess 编码的新手,我发现它比 html 和 css 更令人困惑。我想让我的 url 对 seo 更友好,对我的用户来说更容易。我当前的代码不起作用。我想让我的网址看起来像下面的示例。如果可能,请告诉我,我不想显示我的身份证号码。

示例网址

http://mobile.mixtapemonkey.com/artist?a=96/2-chainz

我可以接受的解决方案

  • .com/2-chainz
  • .com/a/2-chainz
  • .com/artist/2-chainz

    RewriteCond %{THE_REQUEST} \s/+artist\?a=([^&]+)&t=([^\s&]+) [NC]
    RewriteRule ^ a/%2? [R=301,L,NE]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(\d+)/([^/]+)/?$ artist.php?a=$1&t=$2 [L,QSA,NC]
    

【问题讨论】:

  • 如果你想隐藏 ID 号 (96),你将不得不依赖一个处理脚本,它将标题解析为相应的 ID。

标签: .htaccess mod-rewrite url-rewriting url-redirection friendly-url


【解决方案1】:

如果您接受 URL 中带有 ID 的重写,请尝试以下操作:

RewriteEngine On

RewriteCond %{THE_REQUEST} ^GET\ /artist\?a=(\d+)/(\S*) [NC]
RewriteRule ^ a/%1/%2? [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^a/(\d+)/(.*)/?$ artist.php?a=$1/$2 [L,QSA,NC]

它会将 URL:http://mobile.mixtapemonkey.com/artist?a=96/2-chainz 重写为:http://mobile.mixtapemonkey.com/a/96/2-chainz

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-01
    • 2015-10-14
    • 2020-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多