簡體   English   中英

如何使用mod_rewrite重寫url

[英]How to rewrite url using mod_rewrite

我的網址目前看起來像這樣:

http://domain.com/news/articles.php?id=22&category=investments&title=securing-your-future-making-the-right-investment

如何使用mod_rewrite使網址看起來像這樣:

http://domain.com/news/articles/investments/securing-your-future-making-the-right-investment

編輯:也需要包含id變量

在您的.htaccess文件中添加以下內容:

^ / news / articles /([[0-9] +)/(。*)$ secure-you-future-make-the-right-investment $ /news/articles.php?id=$1&category=$3s&title=$2 [L]

不了解這3美元,但您列出的網址中似乎沒有類別,因此我認為它不是必需的。

這應該使它工作;)

#enable mod rewrite
RewriteEngine On
RewriteRule ^/news/articles.php?id=([0-9]+)&category=([a-zA-Z]+)&title=([a-zA-Z]+)$ /news/articles/$2/$1_$3

該ID必須存在於URL中,因此它看起來像:

http://domain.com/news/articles/investments/ {ID} _securing-your-future-making-the-right-investment

祝好運。

暫無
暫無

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

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