問題描述
我正在嘗試重寫站點的 url,我應(yīng)該提到 index.php 現(xiàn)在的工作方式是獲取 p(頁面)參數(shù)并包含適當(dāng)?shù)奈募?
I am trying to rewrite the urls of a site, i should mention that the way index.php works now is getting the p (page) parameter and including the appropriate file.
所以請求一個頁面是這樣的:
So requesting a page is like this:
www.domain.com/index.php?p=home
www.domain.com/index.php?p=search
www.domain.com/index.php?p=profile
www.domain.com/index.php?p=contact
我找到了如何為此創(chuàng)建重寫規(guī)則:
I found how to create a rewrite rule for this:
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?p=$1
所以現(xiàn)在www.domain.com/home會給我主頁
但我還需要為此提供一個友好的網(wǎng)址
But i also need to have a friendly url for this
www.domain.com/index.php?p=profile&id=20
to
www.domain.com/profile/20/profile-friendly-name
or better
www.domain.com/profile/profile-friendly-name
*個人資料友好名稱是指公司名稱
*The profile-friendly-name refers to a company name
要求:
為所有頁面提供友好的 url,例如/home,/contact
To have friendly urls for all pages e.g. /home, /contact
為個人資料頁面提供一個特別友好的網(wǎng)址,其中包含網(wǎng)址中的個人資料名稱
To have a particular friendly url for the profile page with the profile name in the url
我的問題:
如何使用現(xiàn)有的 url 格式 (index.php?p=profile&id=20) 向 url 添加個人資料友好名稱?
How can i add a profile-friendly-name to the url with the existing url format (index.php?p=profile&id=20)?
我可以在那里只有一個唯一的名字嗎(沒有 id),就像我的最后一個例如?
Can i only have a unique name there (without the id), like my last example?
如果我設(shè)法做到了,我是否必須更改所有現(xiàn)有的網(wǎng)址在站點內(nèi)(鏈接、圖像 url、文件)到友好的格式?
If i manage to do that, will i have to change ALL the existing urls within the site (links, urls to images, to files) to the friendly format?
我注意到在應(yīng)用第一個 RewriteRule 之后,一些 css不包括樣式表和 js.怎么了?
I noticed that after applying the first RewriteRule some css stylesheets and js are not included. What is wrong?
推薦答案
RewriteRule ^profile/([0-9]+)/([A-Za-z0-9-]+)/?$ index.php?p=profile&id=$1
應(yīng)該適用于:
www.domain.com/index.php?p=profile&id=20
to
www.domain.com/profile/20/profile-friendly-name
這篇關(guān)于使用 htaccess 創(chuàng)建 SEO 友好的 url的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!