2017-02-07 105 views
0

我想从我的网站创建漂亮的URL,但我仍然在.htaccess中创建了一个漂亮的URL,我很困惑。使用.htaccess文件将原始URL更改为漂亮的URL

原始地址:

1. mysite.com/index.php?mode=frontend&act=viewArtikel&cat=hotnews&year=2017&month=02&link=hello-world 

2. mysite.com/index.php?mode=frontend&act=viewProduct&cat=food&link=pizza 

预计:

1. mysite.com/hotnews/2017/02/hello-world.html 
2. mysite.com/food/pizza.html 

怎么办呢? 在此先感谢 PS:请不要纪念这个职位重复,对不起,我的英语不好

回答

1

尝试下面的规则,

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^([\w-]+)/([\d]{4}+)/([\d]{2}+)/([\w-]+)\.html$ index.php?mode=frontend&act=viewArtikel&cat=$1&year=$2&month=$3&link=$4 [L] 
RewriteRule ^([\w-]+)/([\w-]+)\.html$ index.php?mode=frontend&act=viewProduct&cat=$1&link=$2 [L] 
+0

我在哪里可以得到有关** W的值 - **, ** \ d **?顺便说一句,我可以定义年份和月份只有数字具有特定的长度exp:year [4个字符]和月份[2个字符]? ,在此先感谢 –

+1

请尝试编辑! –

+0

不错,它的工作 –