如何更改网址? htaccess的

时间:2011-11-28 19:33:19

标签: .htaccess mod-rewrite

我有什么

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]

2 个答案:

答案 0 :(得分:6)

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

这将重写以 newsy 开头的所有内容,并在其与html文件之间添加 / czytaj / items

答案 1 :(得分:1)

原则上,您只需创建相应的重写规则:

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

不要忽略[L]标志至关重要。否则你的重写引擎可能陷入无限循环。同样在.htaccess文件的开头,请记得使用以下内容启用mod_rewrite

RewriteEngine On

有关mod_rewrite的更多帮助,建议您查看mod_rewrite-cheatsheet。有关详尽的URl重写指南,请参阅a corresponding page from Apache 2.0 Documentation