简体   繁体   中英

php how to create seo friendly urls

I am new with php language and now I have question How to create SEO url's. I searched from google but can't understand properly that's why I am posting my question.

I have bellow links which is dynamic:

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

Now I want URL something like this:

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

I have .htaccess in my folder and code is:

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]

I hope you can help me.

Thanks.

Put htaccess file on your site root and place this code:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM