我正在尝试重写站点的 url,我应该提到 index.php 现在的工作方式是获取 p(页面)参数并包含适当的文件.
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
我找到了如何为此创建重写规则:
I found how to create a rewrite rule for this:
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?p=$1
所以现在www.domain.com/home会给我主页
但我还需要为此提供一个友好的网址
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
为个人资料页面提供一个特别友好的网址,其中包含网址中的个人资料名称
To have a particular friendly url for the profile page with the profile name in the url
我的问题:
如何使用现有的 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?
如果我设法做到了,我是否必须更改所有现有的网址在站点内(链接、图像 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?
我注意到在应用第一个 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
应该适用于:
www.domain.com/index.php?p=profile&id=20
to
www.domain.com/profile/20/profile-friendly-name
这篇关于使用 htaccess 创建 SEO 友好的 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!