使用.htaccess美化网址

时间:2012-06-04 16:11:30

标签: apache .htaccess mod-rewrite

我有这个链接 http://xxxx.com/yyyy/index.php?class=Applications&function=create

我希望看起来像这样

http://xxxx.com/yyyy/create

我知道我必须使用

上的RewriteEngine

RewriteRule ..................

但由于我是新手,我不知道如何格式化它。

DirectoryIndex index.php order deny,allow Options +FollowSymLinks -MultiViews

 RewriteEngine On RewriteBase /
 RewriteRule ^(XXXXXXXX)/(aaaa)/?$ $1/index.php?class=Applications&function=$2 [L,NC,QSA] 
RewriteRule ^(XXXXXXXX)/(bbbb)/?$ $1/index.php?class=Applications&function=$2 [L,NC,QSA] 
RewriteRule ^(XXXXXXXX)/(cccc)/?$ $1/index.php?class=Applications&function=$2 [L,NC,QSA] 
RewriteRule ^(XXXXXXXX)/(dddd)/?$ $1/index.php?class= test&function=$2 [L,NC,QSA] 
RewriteRule ^(yyyy)/index\.php$ $1 [L,NC]  #this one is not working...

2 个答案:

答案 0 :(得分:1)

通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在.htaccess目录下的DOCUMENT_ROOT中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^(yyyy)/(create)/?$ $1/index.php?class=Applications&function=$2 [L,NC,QSA]

答案 1 :(得分:0)

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /yyyy/
    RewriteRule create index.php?class=Applications&function=create
</IfModule>