搜索引擎友好的 URL [英] Search-Engine Friendly URLs

查看:30
本文介绍了搜索引擎友好的 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力构建我的第一个搜索引擎友好的 CMS.我知道拥有 SEO 站点的最大关键之一可能是拥有对搜索引擎友好的 URL.所以有一个这样的链接:

http://www.mysite.com/product/details/page1

会产生比这样的排名好得多的排名:

http://www.mysite.com/index.php?pageID=37

我知道要像第一个一样创建 URL,我有以下两个选项之一:

  • 使用网络技术(在本例中为 PHP)来创建目录结构
  • 利用 Apache 的 mod_rewrite 插件将这些 URL 传递给 PHP 处理器

就 PHP 而言,我对任何事情都非常满意.但是,我认为第一个选项会更难维护.

有人可以告诉我如何编写 .htaccess 文件,它将:

  • 悄悄地将 SEO URL 定向到处理器脚本
  • 如果请求的 URL 是服务器上的实际目录,则不重定向

还有比我尝试的方法更好的方法吗?

解决方案

您可以使用 .htaccess for apache,在您的 web 根文件夹中创建文件,主要htdocs"命​​名为.htaccess"添加下一个内容

>

重写引擎开启RewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-f重写规则 ^(.*)$ index.php?url=$1 [QSA,L]选项 - 索引</IfModule>

在您的 php 文件中,您可以从 $_GET 访问数据

$_GET['url'];

然后你就可以用数据来解析你需要的东西了.

I am working on building my first search-engine friendly CMS. I know that perhaps one of the biggest keys to having and SEO site is to have search-engine friendly URLs. So having a link like this:

http://www.mysite.com/product/details/page1

will result in much better rankings than one like this:

http://www.mysite.com/index.php?pageID=37

I know that to create URLs like the first one, I have one of two options:

  • use a web technology, in this case PHP, to create a directory structure
  • leverage Apache's mod_rewrite add-on to have these URLs passed to a PHP processor

As far as the PHP goes, I'm pretty comfortable with anything. However, I think the first option would be more difficult to maintain.

Could someone show me how to write an .htaccess file, which will:

  • silently direct SEO URLs to a processor script
  • not redirect if the requested URL is an actual directory on the server

Is there a better way than the way I am trying it?

解决方案

You can use .htaccess for apache, create file in your root folder of web mainly "htdocs" name it ".htaccess" add next content to it

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
    Options -Indexes
</IfModule>

in your php file you can access data from $_GET

$_GET['url'];

Then you can use data to parse what you need.

这篇关于搜索引擎友好的 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆