steamboy
steamboy

Reputation: 1162

.htaccess URL redirect

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 is using the same htaccess.

Thanks!

Upvotes: 2

Views: 9040

Answers (3)

Amit Verma
Amit Verma

Reputation: 41209

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.

Upvotes: 3

Peter O'Callaghan
Peter O'Callaghan

Reputation: 6186

You could utilise mod_rewrite.

RewriteEngine On
RewriteRule ^blog/index\.php/weblog/rss_2\.0/$ /feed/ [R=302]

That should forward the URL to /feed/ on the same domain as the request came in on. Once you're happy it's working you can change the 302 to 301.

Upvotes: 6

derekerdmann
derekerdmann

Reputation: 18242

redirect 301 blog/index.php/weblog/rss_2.0/ http://www.domain.com/feed/

It's that easy! Just make sure that the .htaccess file is located at the web root, which is usually `http://www.domain.com'.

EDIT: For redirecting other pages, just follow the basic format

redirect 301 [path from web root] [full path to the new page]

You can add another line for every page that you want to redirect.

Upvotes: 4

Related Questions