2011-11-28 150 views
1

如何更改网址? htaccess的

newsy/czytaj/items/odbierz-250zl-na-reklame.html 

什么这是我不得不

newsy/odbierz-250zl-na-reklame.html

如何使用mod-rewrite做到这一点?我不明白RewriteRule。

我的.htaccess

RewriteEngine On 
RewriteCond %{REQUEST_URI} (ftp|https?):|/etc/ [NC,OR] 
RewriteCond %{QUERY_STRING} (ftp|https?):|/etc/ [NC] 
RewriteRule .* - [F,L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .*\.html$ index.php [L] 

回答

6
RewriteEngine on 
RewriteRule ^newsy/([^\./]+)\.html /newsy/czytaj/items/$1.html [L] 

这将重写任何与报童开始并添加/czytaj /项目它和HTML文件之间

+0

+1为最快的答案! – jsalonen

+0

我不知道在哪里插入这一行。 –

+0

将它插入在'RewriteEngine On'正下方,您只需要RewriteRule线,因为您已经开启了引擎。 –

1

原则上你刚才创建相应的重写规则:

RewriteRule ^newsy/czytaj/items/(.+) /newsy/$1 [L] 

至关重要不要省略[L]标志。否则你的重写引擎可能会陷入无限循环。另外在.htaccess文件的开头记得,使mod_rewrite有:

RewriteEngine On 

有关mod_rewrite的更多帮助,我建议检查出mod_rewrite-cheatsheet。有关详尽的URl重写指南,请参阅。