php : SEO friendly urls

2019-01-09 02:18发布

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

4条回答
【Aperson】
2楼-- · 2019-01-09 02:29

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

查看更多
叼着烟拽天下
3楼-- · 2019-01-09 02:35

Try this:

<IfModule mod_rewrite.c>
  RewriteEngine On  
  RewriteRule ^.* index.php
</IfModule mod_rewrite.c>
查看更多
地球回转人心会变
4楼-- · 2019-01-09 02:40

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.

查看更多
叛逆
5楼-- · 2019-01-09 02:44

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.

查看更多
登录 后发表回答