php如何创建seo友好的URL

时间:2014-04-08 09:26:12

标签: php .htaccess url-rewriting

我是php语言的新手,现在我有问题如何创建SEO网址。我从谷歌搜索但不能正确理解我发布问题的原因。

我有一些动态的链接:

<a href="http://localhost/mysite/pic?id=31">Page 31</a>
<a href="http://localhost/mysite/pic?id=32">Page 32</a>
<a href="http://localhost/mysite/pic?id=33">Page 33</a>
<a href="http://localhost/mysite/pic?id=34">Page 34</a>
<a href="http://localhost/mysite/pic?id=35">Page 35</a>
<a href="http://localhost/mysite/pic?id=36">Page 36</a>

现在我想要这样的URL:

<a href="http://localhost/mysite/pic/31">Page 31</a>

我的文件夹中有.htaccess,代码是:

RewriteEngine on
# Necessary to prevent problems when using a controller named "index" and having a root index.php
# more here: http://httpd.apache.org/docs/2.2/content-negotiation.html
Options -MultiViews
# Activates URL rewriting (like myproject.com/controller/action/1/2/3)
RewriteEngine On
# Disallows others to look directly into /public/ folder
Options -Indexes
# When using the script within a sub-folder, put this path here, like /mysubfolder/
# If your app is in the root of your web folder, then leave it commented out
RewriteBase /mysite/
# General rewrite rules
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

我希望你能帮助我。

感谢。

1 个答案:

答案 0 :(得分:1)

将htaccess文件放在您的网站根目录并放置此代码:

Options +FollowSymLinks
RewriteEngine on
RewriteRule pic/(.*) pic?id=$1