Search-Engine Friendly URLs
I am working on building my first search-engine friendly CMS. I know that perhaps one o开发者_JS百科f 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.
Yes, the first option would be pretty hard to maintain. If you want to change the header of the pages, you'd need to recalculate all of the pages.
The simplest way to do that would be to have a PHP file named product.php
or product/details.php
and use the $_SERVER\['PATH_INFO'\]
variable to figure out what the client requested.
精彩评论