php:SEO 友好的 url

发布于 2024-09-16 15:03:32 字数 169 浏览 2 评论 0原文

我正在开发一个新项目,我想为此网站创建 SEO 友好的 URL,例如

mysite.com/first_content、mysite.com/second_content。 URL 必须是动态的,这意味着 URL 必须与内容标题相关。我怎样才能做到这一点?是否可以使用 htacess?

谢谢

I am working on a new project, I want to create SEO friendly URL's for this site like

mysite.com/first_content, mysite.com/second_content. URL's must be dynamic which means URL's must related to the content title. How can I done this ? Is is possible to use htacess, ?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

土豪我们做朋友吧 2024-09-23 15:03:32

.htaccess 的示例规则(一旦您确保启用了 mod_rewrite):

  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule (.*) index.php?page=$1 [L]

这些规则匹配任何不存在的文件的 URL,并将其传递到您的脚本。

Sample rules for .htaccess (once you make sure mod_rewrite is enabled):

  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule (.*) index.php?page=$1 [L]

These rules match any URL that isn't an already existing file and passes it to your script.

一抹淡然 2024-09-23 15:03:32

是的,您可以通过使用 .htaccess 来做到这一点。互联网上有大量教程。

用于执行此操作的模块称为 mod_rewrite。它根据正则表达式模式重新路由传入请求。

这些教程很好地解释了这一点:
1. URL 重写初学者指南
2. http://www.easymodrewrite.com/guide-syntax

您还需要如果您打算使用 mod_rewrite,请了解正则表达式的基础知识。该网站是最好的正则表达式资源之一。
- 正则表达式教程

Yes, you can do that by using .htaccess for that. There are plenty of tutorials available on Internet.

The module used to do that is called mod_rewrite. It re-routes incoming requests based on regular expression patterns.

These tutorials explains it pretty well:
1. A Beginner's Guide to URL Rewriting
2. http://www.easymodrewrite.com/guide-syntax

You will also need to know the basics about regular expressions if you plan to use mod_rewrite. This site is one of the best regular expression resources out there.
- Regular Expression Tutorial

丢了幸福的猪 2024-09-23 15:03:32

在 .htaccess 中:

Options +FollowSymLinks

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (.*)/(.*)$ index.php?name=$2
</IfModule>

其中 $2 包含第二个括号的内容。

In .htaccess:

Options +FollowSymLinks

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (.*)/(.*)$ index.php?name=$2
</IfModule>

Where $2 has the content of the second parentheses.

享受孤独 2024-09-23 15:03:32

试试这个:

<IfModule mod_rewrite.c>
  RewriteEngine On  
  RewriteRule ^.* index.php
</IfModule mod_rewrite.c>

Try this:

<IfModule mod_rewrite.c>
  RewriteEngine On  
  RewriteRule ^.* index.php
</IfModule mod_rewrite.c>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文