创建使用htaccess的搜索引擎友好的URL友好、搜索引擎、htaccess、URL

2023-09-02 00:30:32 作者:于酒说心事

我想重写一个网站的网址,我要指出的index.php的工作方式,现在是越来越P(页)参数,包括相应的​​文件。

因此​​请求一个页面是这样的:

  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
 

我发现如何创建这样的重写规则:

 重写规则^([A-ZA-Z0-9  - ] +)?/ $的index.php P = $ 1
 

所以现在的 www.domain.com/home 会给我的首页

但我也需要有一个友好的URL为这个

  www.domain.com/index.php?p=profile&id=20

至

www.domain.com/profile/20/profile-friendly-name

或更好

www.domain.com/profile/profile-friendly-name
 
送你6个好用但小众的搜索引擎,轻松吊打百度 让天下没有搜不到的东西

*配置文件友好的名称指的是一个公司的名字

要求:

要具有友好的URL如所有页面/家,/接触

要具有特别的友好的URL与个人资料页面 在URL配置文件名称

我的问题:

我如何添加一个配置文件友好的名称到URL与现有的URL格式(的index.php P =轮廓和放大器;?ID = 20)?

我只能有唯一的名称有(无ID),就像我上次 例如?

如果我能做到的是,我将不得不改变所有现有的网址 网站内(链接,网址,图像,文件),以友好 格式?

我注意到,将第一重写规则一些CSS后 样式表和js不包括在内。什么是错的?

解决方案

 重写规则^配置文件/([0-9] +)/([A-ZA-z0-9-] ??+)/ $的index.php P =轮廓和ID = $ 1
 

应该为:

  www.domain.com/index.php?p=profile&id=20

至

www.domain.com/profile/20/profile-friendly-name
 

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

so now www.domain.com/home would give me the home page

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

Requirements:

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

My questions:

How can i add a profile-friendly-name to the url with the existing url format (index.php?p=profile&id=20)?

Can i only have a unique name there (without the id), like my last example?

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?

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

Should work for :

www.domain.com/index.php?p=profile&id=20

to

www.domain.com/profile/20/profile-friendly-name