How it Works
Static URLs are known to be better than Dynamic URLs because of a number of reasons
1. Static URLs typically Rank better in Search Engines.
2. Search Engines are known to index the content of dynamic pages a lot slower compared to static pages.
3. Static URLs are always more friendlier looking to the End Users.
Open rewrite in your apache conf
Checkout the following lines
#line1
Options FollowSymLinks
AllowOverride All
Allow from all
#2
LoadModule rewrite_module modules/mod_rewrite.so
make sure the options is followsyslinks ,allowoverride is all and rewrite_module is loaded. Then make a file named .htaccess and copy it in your website root folder.
you should know some basic rules about apache rewrite, here’s some clips i quote from the Doc
文本
. 任意一个单字符
[chars] 字符类: “chars”中的任意一个字符
[^chars] 字符类: 不在”chars”中的字符
text1|text2 选择: text1 或 text2
量词
? 前面的字符出现 0 或 1 次
* 前面的字符出现 0 或 N 次(N > 0)
+ 前面的字符出现 1 或 N 次(N > 1)
分组
(text) text 组
(常用于设置一个选择的边界,或用于生成后引用:
在RewriteRule中可以用 $N 引用第N个分组)
锚
^ 锚定到行首
$ 锚定到行尾
转义
\c 对给定的字符c进行转义
(比如对”.[]()”进行转义,等等)
for more info you can visit the offical doc , http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/mod_rewrite.html
than here is a simple example:
if you want this url http://www.widgets.com/product.php?categoryid=1 convert to http://www.widgets.com/product/categoryid/(Any Value)/
copy the following code in your .htaccess
Options +FollowSymLinks
RewriteEngine on
RewriteRule product/categoryid/(.*)/ product.php?categoryid=$1
RewriteRule product/categoryid/(.*) product.php?categoryid=$1
now the new url should work, that’s all,folks~