使用 htaccess 创建 SEO 友好的 url

Creating SEO friendly urls using htaccess(使用 htaccess 创建 SEO 友好的 url)
本文介绍了使用 htaccess 创建 SEO 友好的 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试重写站点的 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

要求:

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

  1. 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

我的问题:

  1. 如何使用现有的 url 格式 (index.php?p=profile&id=20) 向 url 添加个人资料友好名称?

  1. 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)