.htaccess URL redirect

后端 未结 3 1363
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-04 04:20

How can I redirect http://domain.com/blog/index.php/weblog/rss_2.0/ to http://www.domain.com/feed/ with .htaccess?

The website has 3 domains pointing to it and all

3条回答
  •  长情又很酷
    2020-12-04 04:48

    You can also use RedirectMatch directive of Mod-alias to redirect a url from location to another.

    forexample : to redirect from http://example.com/file.php to http://example.com/folder/file.php

    You would use the following code in htaccess :

     RedirectMatch 301 ^/([^.]+)\.php$ http://example.com/folder/$1.php
    

    Explaination : RedirectMatch directive uses regular expression pattern to match against the url path. in the example above our pattern ^/([^.]+).php$ matches against the url path /file.php , ^ means start of line. then we match / , ([^.]+) is a capture group it matches any characters excluding dot ,and saves the value as $1 for reuse in target url, in the example above it captures name of file. .php matches .php litterly. we need to ecape the dot with a back slash because it is a special word in regex. $ means end of line/string.

提交回复
热议问题