使用htaccess创建SEO友好的URL

Mic*_*kis 2 php url .htaccess mod-rewrite seo

我试图重写网站的网址,我应该提到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
Run Code Online (Sandbox Code Playgroud)

我找到了如何为此创建重写规则:

RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?p=$1
Run Code Online (Sandbox Code Playgroud)

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

但我还需要一个友好的网址

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
Run Code Online (Sandbox Code Playgroud)

*个人资料友好名称是指公司名称

要求:

  1. 为所有页面提供友好的URL,例如/ home,/ contact

  2. 为个人资料页面提供特定的友好网址,并在网址中包含个人资料名称

我的问题:

  1. 如何使用现有的url格式(index.php?p = profile&id = 20)向url添加profile-friendly-name?

  2. 我可以只有一个唯一的名称(没有id),就像我上一个例子一样吗?

  3. 如果我设法做到这一点,我是否必须将网站中的所有现有网址(链接,网址到图片,文件)更改为友好格式?

  4. 我注意到在应用第一个RewriteRule后,一些css样式表和js不包括在内.怎么了?

Ama*_*mal 6

RewriteRule ^profile/([0-9]+)/([A-Za-z0-9-]+)/?$ index.php?p=profile&id=$1
Run Code Online (Sandbox Code Playgroud)

应该工作:

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

to

www.domain.com/profile/20/profile-friendly-name
Run Code Online (Sandbox Code Playgroud)