Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RewriteRule for 301 redirect

I went through all the answered threads on rewrite rule problem. Tried the suggestions, But I still don't know what I am doing wrong.

I want to make a 301 redirect of our old URLs to the new ones. Example:

old url : http://www.xyz.com/abc/topics.html
new url : http://www.xyz.com/index.php#first

I am trying following rule in .htaccess:

RewriteEngine on
RewriteRule ^\/abc\/(.+)$ http://www.xyz.com/index.php#first [L,R=301]

Any advice is highly appreciated

like image 385
mooglife Avatar asked Oct 19 '11 08:10

mooglife


People also ask

What is a 301 .htaccess redirect?

A 301 Permanent Redirect permanently redirects one URL to another. You set up a 301 redirect using . htaccess to send visitors to a new URL and tell search engines that a page has moved so that the new page can be properly indexed.

Should I enable 301 .htaccess redirect?

The . Because the WordPress 301 redirect is not always reliable, we recommend issuing the 301 redirect via your . htaccess file. Another benefit is that the . htaccess redirect is slightly faster than redirecting via PHP, because it is loaded even before the rest of the page.


2 Answers

Try this:

RewriteRule ^abc\/(.+)$ http://www.example.com/index.php#first [L,R=301,NE]
like image 168
Josep Valls Avatar answered Oct 21 '22 20:10

Josep Valls


You can, of course, do it by "mod_rewrite", but in this situation I'd suggest you use mod_alias as it is faster and simpler (see this SO response: mod_rewrite or mod_alias?)

Like this:

Redirect permanent /abc http://www.xyz.com/index.php#first
like image 32
naivists Avatar answered Oct 21 '22 20:10

naivists