.htaccess 重写漂亮 url
.htaccess rewrite pretty url
我是 .htaccess 编码的新手,我发现它比 html 和 css 更令人困惑。我想让我的 url 对 SEO 更友好,对我的用户来说更容易。我当前的代码不起作用。我想让我的 urls 看起来像下面的示例。让我知道是否可能,我不想显示我的身份证号码。
示例url
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=&t= [L,QSA,NC]
如果您接受使用 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=/ [L,QSA,NC]
它会将 URL: http://mobile.mixtapemonkey.com/artist?a=96/2-chainz
重写为: http://mobile.mixtapemonkey.com/a/96/2-chainz
.
我是 .htaccess 编码的新手,我发现它比 html 和 css 更令人困惑。我想让我的 url 对 SEO 更友好,对我的用户来说更容易。我当前的代码不起作用。我想让我的 urls 看起来像下面的示例。让我知道是否可能,我不想显示我的身份证号码。
示例url
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=&t= [L,QSA,NC]
如果您接受使用 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=/ [L,QSA,NC]
它会将 URL: http://mobile.mixtapemonkey.com/artist?a=96/2-chainz
重写为: http://mobile.mixtapemonkey.com/a/96/2-chainz
.