簡體   English   中英

使用 .htaccess 創建 SEO 網址

[英]Creating SEO urls with .htaccess

我想為我的博客創建 SEO url 我的博客 url 就像http://localhost/test/blog.php?blogId=5我想將其轉換為博客標題。

我目前正在 .htaccess 頁面中嘗試此操作,但這不起作用

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?u=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?u=$1
RewriteEngine ON
RewriteRule ^([a-zA-Z0-9_-]+)$ blog.php?blogId=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ blog.php?blogId=$1

奇怪的是,我為用戶 ID 嘗試了類似的代碼並且它起作用了。

your URL should be 
http://localhost/test/1

RewriteRule ^test/([a-zA-Z0-9_-]+)/$ blog.php?blogId=$1 [NC]

試試這樣寫...

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?u=$1 [NC,L] # for user id's no slash
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^([a-zA-Z0-9_-]+)/$ blog.php?blogId=$1 [NC,L] # for blog with slash

指向用戶 ID 的鏈接看起來像/2

指向博客文章的鏈接看起來像/2/

快樂編碼!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM