htaccess URL重定向 - 想要从URL中删除单词

时间:2013-08-27 05:45:58

标签: regex apache .htaccess redirect mod-rewrite

我想将一些网址重定向到不同的网址。例如

http://www.mydomain.com/some-text-2-rss/
http://www.mydomain.com/another-text-rss
http://www.mydomain.com/sample-rss/
http://www.mydomain.com/dummy-content-rss
http://www.mydomain.com/some-folder-1/my-text-rss
http://www.mydomain.com/another-folder/some-text-rss/

TO

http://www.mydomain.com/some-text-2/
http://www.mydomain.com/another-text
http://www.mydomain.com/sample/
http://www.mydomain.com/dummy-content
http://www.mydomain.com/some-folder-1/my-text
http://www.mydomain.com/another-folder/some-text/

即如果任何网址的结尾是'-rss'或'-rss /',我想从网址中删除'-rss'。

先谢谢。

1 个答案:

答案 0 :(得分:0)

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

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

RewriteRule ^(.+?)-rss(/?)$ /$1$2 [L,NC,R]