Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

php - Search-Engine Friendly URLs

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...