If you are porting over an existing website to Drupal, one consideration is how you redirect the old page URLs to the appropriate pages on the Drupal version of the site. If you don't want to create custom rewrite paths within Drupal for those nodes -- or perhaps cannot due to clean URLs or filename suffixes -- then 301 redirects are considered the best way to handle redirected pages, for they inform search engines to update their databases with the new paths. This way, you should not risk your search engine pagerank or lose site visitors with 404 "not found" errors.

However, 301 redirects cannot be done using the common approach. Yet establishing 301 redirects is quite easy, provided you have mod_rewrite enabled in your .htaccess file.

How to create 301 redirects in Drupal Apache mod_rewrite

Edit your .htaccess file in a text editor. [Note: Be sure to save the file in "UTF-8" format.]

In the file, you will find the commands:

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  # Modify the RewriteBase if you are using Drupal in a subdirectory and
  # the rewrite rules are not working properly.
  #RewriteBase /drupal

RewriteBase /

Immediately after that code -- and before the Drupal-provided "Rewrite old-style URLs" commands -- add your rewrite rules using the following format:

#custom redirects

RewriteRule ^old/URL/path$ http://example.com/new/path [R=301,L]

#end custom redirects

Note the convention: The old path is simply the path off the root. The new path is the full path, including the domain. The [R=301,L] code is the 301 redirect instruction. (axbom notes: "The 301 tells browsers and spiders it is a permanent redirect, and the L ensures that no other rewrites are processed on the URL before it reaches Drupal; Hence place this code above Drupal 's own URL rewrite, but below the command RewriteEngine on.")

If you have more paths to add, insert the rewrite commands as their own line as above.

For more information, see the forum thread at http://drupal.org/node/16084 [from where I drew this information]

Comments

Sutharsan’s picture

You have carefully rebuild your existing website in Drupal. Matched the existing path to Drupal path. With a few exceptions of course. But redirecting all those pages with hard coded redirects as above is a lot of work. Well Apache can crack this nut for you. The below .htaccess snippets are an extention to ones the above.

Lets say you have plenty of pages in your existing site like /foo/foo_detail.html and some like /bar/index.html.
In your new Drupal site this same page content is found with path like: /foo/foo_detail and /bar.

To redirect from the old to the new you place this code in your .htaccess file. Make shure to place it prior to the standard Drupal redirects or it will not work.

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  #custom redirects

  RewriteRule (.*)/index\.html$ http://www.mysite.nl/$1 [R=301,L]
  RewriteRule (.*)\.html$ http://www.mysite.nl/$1 [R=301,L]

  #end custom redirects

Ok, the most of your redirects are fixed. Now the exceptions.
First the easy ones. The pages where the new path is nothing like the old one, must be hard coded and come first. Old: /this_is_hot_news/index.html, is now found in: /news.
Your own bloud, sweat and tears, .php files are now taken care of by Drupal modules and path. Just use the same trick ase above but now with 'php' instead of the 'html'.

The looks like:

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  #--------------- custom redirects -----------------
  #hard coded  
  RewriteRule ^this_is_hot_news/index\.html http://www.mysite/news [R=301,L]

  RewriteRule (.*)/index\.html$ http://www.mysite.nl/$1 [R=301,L]
  RewriteRule (.*)\.html$ http://www.mysite.nl/$1 [R=301,L]

  RewriteRule (.*)/index\.php$ http://www.mysite.nl/$1 [R=301,L]
  RewriteRule (.*)\.php$ http://www.mysite.nl/$1 [R=301,L]

  #end custom redirects

Finally, you have some dynamic pages rebuilt into Drupal with URL like: /photo?series=2 and /photo?series=3, etc. Whell, this requires serious redirecting. The RewriteRule as we used above does not take the part behind the questionmark into account. The code below does the trick.


  RewriteCond %{THE_REQUEST} series=2
  RewriteRule . http://www.mysite.nl/node/75? [R=301,L]
  RewriteCond %{THE_REQUEST} series=3
  RewriteRule . http://www.mysite.nl/node/72? [R=301,L]

Note the question mark after the node number. This is needed there to clear the query string of the URL. Place this code right below the hard coded rewrites (the /news path in the example above).

Good luck. I hope this saves you the time it took me to redirect my first site!

-- Erik

psaint’s picture

Actually I've tried Sutharsan approach and it did not work for me. To make it useful I had to use sth like this:

RewriteCond %{QUERY_STRING} ^q=/node/subnode/file_name.html$
RewriteRule ^$ http://www.mysite.com/node/100? [R=301,L]

Breaking this down we will get:
%{QUERY_STRING} - connection and request variable in Apache which keeps the query part of url i.e. for the following url http://www.mysite.com/?q=oneOfPages.html
it will return everyting after 'q' mark.

^ - means starts with (in RegEx)
$ - ends with (in RegEx)
^$ - empty string (in RegEx)
[R=301] - force external redirection (301 specifies what HTTP response code will be returned - default is 302 - moved temporarily)
[L] - stop processing rewrite rules on this rule (we want to avoid any other rewrite commands to be used on our newly generated URL)

Important
Remember about '?' at the end of url to which you are redirecting. If you don't include this trailing '?' all query you from the old url will be appended to new url and you will get invalid redirection.

Hope this will help some of you.

yngens’s picture

psaint,

how should i redirect url's with variable from an old site like: /view.php?i=[id]
to drupal's: /index.php?q=node/[id]

?

bethakoch1’s picture

Google web master has just flagged me for duplicate content and duplicate titles for a url that I haven't the foggiest where it came from. I would like to do a redirect whenever this url comes up because I think I may have some valuable back links going to this weird url. Heres the weird url and where I would like to have it redirected to. I am not very versed at htaccess rules but if someone gave me something I could cut and paste into my htaccess custom redirect location I could handle it. I am using drupal 6x with fusion.

weird url:

http://www.fourseasonshvacr.com/?userId=info%3Adoi%2F10.1371%2Faccount%2...

would like it redirected to:

http://www.fourseasonshvacr.com

Thanks in advance for the help

bevin’s picture

I have lot of html pages under old domain, since my domain has changed to new one, those html pages dynamically stick with the new one, But I dont have these pages except in cache, So I decide redirect them to a new url which is a proper node in drupal, and I use this command, which does work well. please free to try this.

RewriteRule ^oldpath/(.*)\.html$ http://newpath/ [R=301,L]

cheers

holeepassion’s picture

On shared hosting server, so for example my addon website becomes http://www.maindomain.com/addon.com/etc

Could I

RewriteRule ^http://www.maindomain.com/addon.com/(.*)\.html$ http://www.addon.com/ [R=301,L]

Thanks heaps in advance

Cheers

oldmanpants’s picture

What if you change the name of a taxonomy term, and you need to redirect urls relating to the old taxonomy term to the new term?

Eg: mysite.com/dogs is changed to mysite.com/cats, where dogs and cats are taxonomy terms that are displayed via the default taxonomy term view (views module).

This is working for me...

  # uncomment the following line:
  RewriteBase /
  
  #custom redirects
  RewriteRule ^oldTaxonomyTermURL/(.*)$ http://mysite.com/newTaxonomyTermURL/$1 [R=301,L]
  #end custom redirects
pieterbezuijen’s picture

There is a module where you can enter the old pages and the new drupal path, in this way you don't have to put it in the .htaccess, and you don't have any trouble when upgrading your Drupal installation.

http://drupal.org/project/path_redirect

thewass’s picture

Hi,

ive been looking at a lot of drupal threads about 301 redirects for old links and i wondered why there is so much on .htaccess rules when there is the path_redirect module avaialble. One assumption I made is that most of these htaccess articles are written before the path-redirect module was made. But i just wanted to check that the .htaccess rules are not in some way cleaner and more SEO friendly than the path_redirect. Does this module send 301 responses directly to the browser/spider or are there any kind of intermediary responses that are not as clean as .htaccess rules.

If my verbal garbage does not make any sense i apologise, im just trying to get my head round the best way to keep alive my old static links which have been indexed by SE's. I only have a handful of pages and no user generated content (yet) so its not an issue to manually create redirects. Dont think i need pathauto as i can create alias' manually and use global-redirect to make sure they are the only links used. ps. Can the path-redirect module stop //example.com as opposed to //www.example.com or does that need a .htaccess rule?

Thanks in advance to all.

dgale’s picture

I have a situation where I am converting a site from .NET. I have a slew of pages that are something like

http://ww.mysite.com/page.aspx?pageId=01
http://ww.mysite.com/page.aspx?pageId=45
http://ww.mysite.com/page.aspx?pageId=543

but I need them to be 301 redirected to something like:

http://ww.mysite.com/news/this-is-the-new-page
http://ww.mysite.com/events/i-am-writing-about-stuffs
http://ww.mysite.com/news/something-happened-today

I've set up my new content types to have a CCK field called "OldPageId" What I'd like to be able to do is handle the request for the old .NET pages, extract the pageId, look for the node in the drupal database based on that Id, and then redirect.

I could enter all redirects using that module (or in the .htaccess file), but it's like thousands of entries. I feel like this is something that should be fairly trivial . . . but I don't have enough experience with PHP or Apache or drupal to know the best way to go about this.

Any have any thoughts or know of a module that might do something like this?

thewass’s picture

I know it is possible, although im not the man to help you with it. I have been reading a drupal development book. It seems to me like the way to do this would be to create your own custom module.

This would use one of the drupal "hooks" to grab the incoming url i.e.

pseudo-code

function(mymodule_url_request_hook)
{
  if(args(0) == 'pageId' && is_numeric(args(1))
  $res = db_query('SELECT nid FROM node WHERE oldID='arg(1)')
  $node = db_result($res)
  node_load($node);
}

remembering of course to escape your url arguments for malicious input
Do an sql search on the database for "oldID", returning the new node ID if found. You then use node_load(node_id) to load the corresponding node.

Although this is a very simple pseudo-code way of stating what you have to do, it would require more research and is probably not jsut as easy as that to redirect pages but it is definitely possible.

Dret’s picture

Ho to all!

I need to make a 301 redirect of a single (old) url to a new one.

How I have to write the rule and where i have to put in .htaccess drupal file?

I tryed with something like this:

Redirect /reviews/old_name_of_review /reviews/new_name_of_reviews [R=301,L]

But everytime gives me a 500 internal error and the site become unaccessible.

Thanks!
Bye!

1websitedesigner’s picture

I've had the same problem, any suggestions would be really handy. I can redirect .php pages and .html pages easily, but is there a way to redirect a Drupal page (i.e. with no .html / .php on the end) to a new Drupal page by modifying the .htaccess file?

I've got pathauto installed, hence using the other module recommended isn't an option, as the 2 aren't compatible currently (though it looks like they will be soon).

Thanks!

SWMdave’s picture

I just came back in here because I spent hours a few months ago trying to fix a Not Found with a 301 redirect. I am no more savy than the next guy so I though I would show where I have had success with this on 2 drupal sites so far. Here is what my code says.

"RewriteRule ^upcoming/newest/SEO$ http://www.karmalynx.com [R=301,L]"

just substitute your sites info for mine

Here is what is posted on KarmaLynx.com. That goes into more detail.

This comes from reading many unanswered questions in the drupal.org community discussion area. I noticed that not many people were able to get their 301 redirects to work properly. I read incorrect answers many times over. Here is a quick an easy version. I have also included a 301 redirect that this site karmalynx.com uses so you can see exactly what you will need to enter into your .htaccess file to have success.

First here is what is listed in the Drupal information how to section under the title, "Redirecting specific pages to new URLs (301 redirects in Drupal)"


Here is the information from the Drupal Page:

    In the file, you will find the commands:

    # Various rewrite rules.
    <IfModule mod_rewrite.c>
      RewriteEngine on

      # Modify the RewriteBase if you are using Drupal in a subdirectory and
      # the rewrite rules are not working properly.
      #RewriteBase /drupal

    RewriteBase /


    Immediately after that code -- and before the Drupal-provided "Rewrite old-style URLs" commands -- add your rewrite rules using the following format:


    #custom redirects

    RewriteRule ^old/URL/path$ http://yourdomain.com/new/path [R=301,L]

    #end custom redirects


Next the instructions say:

    Note the convention: The old path is simply the path off the root. The new path is the full path, including the domain. The [R=301,L] code is the 301 redirect instruction. (axbom notes: "The 301 tells browsers and spiders it is a permanent redirect, and the L ensures that no other rewrites are processed on the URL before it reaches Drupal; Hence place this code above Drupal 's own URL rewrite, but below the command RewriteEngine on.")

    If you have more paths to add, insert the rewrite commands as their own line as above.

This can be confusing since they explained it by saying "old path is simply the path off the root." So here is where I believe a lot of people will be helped:

First you want to find this section in your .htaccess file: (this assumes you have made no changes yet)

    # Various rewrite rules.
    <IfModule mod_rewrite.c>
      RewriteEngine on

      # If your site can be accessed both with and without the 'www.' prefix, you
      # can use one of the following settings to redirect users to your preferred
      # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
      #
      # To redirect all users to access the site WITH the 'www.' prefix,
      # (http://example.com/... will be redirected to http://www.example.com/...)
      # adapt and uncomment the following:
      #RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
      #RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
      #
      # To redirect all users to access the site WITHOUT the 'www.' prefix,
      # (http://www.example.com/... will be redirected to http://example.com/...)
      # uncomment and adapt the following:
      # RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
      # RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

      # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
      # VirtualDocumentRoot and the rewrite rules are not working properly.
      # For example if your site is at http://example.com/drupal uncomment and
      # modify the following line:
      # RewriteBase /drupal
      #
      # If your site is running in a VirtualDocumentRoot at http://example.com/,
      # uncomment the following line:
      #RewriteBase /
    


    RewriteRule ^Money$ http://www.karmalynx.com/BusinessPolitics [R=301,L]


    RewriteRule ^upcoming/newest/Computer$ http://www.karmalynx.com [R=301,L]


    RewriteRule ^upcoming/newest/SEO$ http://www.karmalynx.com [R=301,L]


    RewriteRule ^Computer/Drigg_Powered_logo_gone_and_error_in_logs$ http://www.karmalynx.com [R=301,L]




      # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_URI} !=/favicon.ico
      RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    </IfModule>

Above We have highlighted in red what you need to add to do a very simple 301 redirect. Thje green text is the "OLD/URL/path" from the instructions. The very important part to executing this redirect is to make sure you keep the " ^ " in the front and make sure you end with a " $ ". Also you want to add the Rewrite rules where we added them above. In the drupal forum, the missing " $ " really seemed to be throwing people off.

 

That should do it, I hope it helps someone out.

bwv’s picture

@SWMdave :

Brilliant, thank you!

Dret’s picture

Great!

Thanks a lot! :D

bethakoch1’s picture

So many assume so much about their audience. You have taken a babe in Drupal and made sense out of a difficult project for me by giving me baby steps. THANK YOU THANK YOU for taking the time to show us exactly how it should look. You should be an instructor.

TechPro’s picture

Hi,

In my .htaccess file, I just had mod_supho.c as below:

<IfModule mod_suphp.c>
	suPHP_ConfigPath /home/examplesite/php.ini
	<Files php.ini>
		order allow,deny
		deny from all
	</Files>
</IfModule>

So, to make redirect work, I added one more IfModule just below the existing module for mod_supho.c like below:

<IfModule mod_suphp.c>
	suPHP_ConfigPath /home/examplesite/php.ini
	<Files php.ini>
		order allow,deny
		deny from all
	</Files>
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on

 #custom redirects
 
 RewriteRule ^test$ https://www.newexamplesite.com/new [R=301,L]
 
 #end custom redirects
</IfModule>

Using above module I am trying to redirect http://www.examplesite/test to https://www.newexamplesite.com/new

This is not working for me. I am using Drupal version 6. Is there any module I need to enable to make redirect work?

Shashwat Purav’s picture

Worked for me. Thank you. :)

Thank You,
Shashwat Purav

joegml’s picture

To all ye wandering souls seeking solutions to your lost pages:

It seems like there's some confusion around this important topic. I ran the top listed solution as outlined (watch the code placement) and it ran fine.

I had installed a custom redirect at the cPanel level on Hot Drupal, which dropped the redirect statement at the end of the .htaccess file which did not work. I think HD did the intelligent default thing, but Drupal sometimes doesn't like the intelligent default ;-)

This is really important when migrating to a new site when you've got old legacy links, especially if they've got high traffic!

Happy redirection.

Dret’s picture

I tryed with success with path like this:

RewriteRule ^main/contact$ http://example.com/new/path [R=301,L]

But didn't work with this:

RewriteRule ^main/default.aspx\?Action=solution$ http://example.com/new/path [R=301,L]

The problem seems to be the old dinamics .aspx type of url...

Do Someone has ideas about?
Thanks!

Dret’s picture

Found a solution, with this:

RewriteCond %{THE_REQUEST} Action=solution
RewriteRule  . http://example.com/new/path [R=301,L]

Now a new question: I have a lot of page with request like "Action=somethings", how can I write a single Condition with many rule for different request?

Example, i tryed something like this but didn't works:

RewriteCond %{THE_REQUEST} Action=
RewriteRule  ^solution$ http://example.com/new/path [R=301,L]

Thanks!

yudarik’s picture

Hi guys,
I'm have two drupal sites that one of them sits on the main domain directory (public_html), and the other sits on a sub domain (located on the sites/all folder). I've already tried all of the solutions mensioned here, but none of them worked for me. Every change I made to the .htaccess file is causing an "Internal Server Error", so I need to roll-back the changes.

This is what I'm using (betwin the "" tags, for my redirects:

RewriteRule ^content/%D7%A7%D7%95%D7%A8%D7%A1-%D7%90%D7%99%D7%A4%D7%95%D7%A8-%D7%9E%D7%A7%D7%A6%D7%95%D7%A2%D7%99$ http://school.breeze.co.il/content/%D7%9E%D7%97%D7%9C%D7%A7%D7%AA-%D7%A7... [R=301,L]

RewriteRule ^content/%D7%9C%D7%99%D7%9E%D7%95%D7%93-%D7%90%D7%99%D7%A4%D7%95%D7%A8-%D7%A7%D7%91%D7%95%D7%A2$ http://school.breeze.co.il/content/%D7%9E%D7%97%D7%9C%D7%A7%D7%AA-%D7%A7... [R=301,L]

I'm missing something or am I just can't get the point it should work on...
By the way this what the Error log says:
[Sun Jan 09 14:20:28 2011] [alert] [client 84.108.241.195] /home/mydomainUsername/public_html/.htaccess: Invalid command '\xef\xbb\xbf#', perhaps misspelled or defined by a module not included in the server configuration
Can somebody help me? cause I'm confused.
Thanks.

gr33nman’s picture

Let's put it into something concrete.
I have a page:
http://www.productpolicy.org/content/about-ppi

I've just renamed the page:
http://www.productpolicy.org/content/about-us

I don't want to lose traffic that may come from 'about-ppi' so I want to permanent redirect in .htaccess.
Ordinarily, I would do this:
redirect 301 /content/about-ppi http://www.productpolicy.org/content/about-us
But this doesn't work with drupal, so I found this thread.

I've tried numerous combinations with the following nearly identical examples:

RewriteRule ^/content/about-ppi$ http://www.productpolicy.org/content/about-us? [R=301,L]
RewriteRule ^/content/about-ppi http://www.productpolicy.org/content/about-us? [R=301,L]
RewriteRule ^/content/about-ppi$ http://www.productpolicy.org/content/about-us [R=301,L]

etc.

All of them end up here:
http://www.productpolicy.org/content/about-us?q=content/about-ppi
A 404 off the about-us page.

This is how it's currently set up in .htaccess:

<IfModule mod_rewrite.c>
  RewriteEngine on
  # Lot's of geek-speak here...

  # My hard coded rewrites below
  RewriteRule ^/content/about-ppi$ http://www.productpolicy.org/content/about-us? [R=301,L]

  # Drupal's important rewrites here...
  # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

I'd be grateful if someone would just tell me what I've missed. I know it's simple, but sometimes it takes a second pair of eyes.

ahimsauzi’s picture

Your .htaccess rule should look like this:

RewriteRule ^/content/about-ppi$ http://www.productpolicy.org/content/about-us [R=301,L]

Hope this help someone...

itkadmin’s picture

Would there be any issue with the redirect pointing to the NID and letting the Global Redirect module look after the clean URL?

i.e. RewriteRule ^old/URL/path$ http://example.com/node/123 [R=301,L]

Global Redirect should then display http://example.com/content/title-of-page

Andrés Chandía’s picture

Hi there, I have next scenario:
Drupal 7,
mydomain.org and mydomain.net, both pointing to the same ip, so either you visit .org or .net you arrive to the same place.
I already have rewrite rule mydomain.net > www.mydomain.net (which comes at the .httaccess file)
and I would like to have:

mydomain.net > www.mydomain.net
mydomain.org > www.mydomain.net
www.mydomain.org > www.mydomain.net

all three rules at the same .httpaccess file.

I've been playing around with the .httpaccess file with no success, I would appreciate very much if you can help me with this issue.

Thanks in advance.

@ch

Andrés Chandía’s picture

I have found the way to solve part of the problem:

Adding this rule line:

RewriteRule (.*)\.org http://www.mydomain.net/$1 [R=301,L]

now if go to any of these urls: mydomain.net | mydomain.org
I end up at: www.mydomain.net

But I can not find the way to go to www.mydomain.org finishing up at www.mydomain.net
Help will be valuable...

@ch

VintageVictory.com’s picture

Hello I copied & pasted the code as follows.
But nothing happens?
Help!
G

#custom redirects

#RewriteRule ^/profile/oldname$ http://website.com/profile/NewName [R=301,L]

#end custom redirects

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


php_value max_execution_time 30
php_value max_input_time 60
php_value memory_limit 128M

# $Id: .htaccess,v 1.90.2.5 2010/02/02 07:25:22 dries Exp $

unrev.org’s picture

I just wanted to mention quickly here (someone mentioned it above but only about the D6 module) that there are modules that can manage this kind of thing.

Drupal 6: http://drupal.org/project/path_redirect (links to many related modules)
Drupal 7: http://drupal.org/project/redirect

While on the topic, be sure to also have a look at:

http://drupal.org/project/globalredirect

Even though the global redirect module isn't specifically for creating 301 redirects, it is a great module to have regarding paths and SEO.

Nice to have a module to do this because, boy, you can really mess things up quick mucking about in the .htaccess file, as I know from experience!

smartsystems160’s picture

i need a redirect rule that says:

Redirect www.example.com/subdomain/user/[uid] TO www.example.com/user/[uid] which redirects all users from sub-domain to primary domain.

My use case? I built a new subdomain and shared my user tables to use primary domain, but i dont want users to have a separate user profile page on the subdomain, so when you click on a username on the subdomain, i want you to be redirected to the primary domain to view the user profiles instead of the profile page on the subdomain. I dont need users to access their account page on the subdomain, instead they should go to the primary domain since the same change happens on subdomain. and why dont i want to replicate the profile page of the primary domain on the subdomain? Because i built the profile page on the primary domain using panels, views, etc and i dont want to start enabling and using these modules on the subdomain. and why did i create a subdomain rather than use the modules on the primary domain? because the modules are many and they are slowing down my primary domain.

The following rule works for user 1 only:

RewriteRule ^user/1$ http://example.com/user/1 [R=301,L]

How do i make the rule work for all users? Thanks for your help.

Energy 313’s picture

I´ve done some url changes to some of the categories on my website. They have all in common that they starts with:
/?side=kategori&kategori=

I’ve tried:
RewriteRule ^?side=kategori&kategori=kontaktannonser_elsker$ http://www.dinstartside.no/?side=kategori&kategori=kontaktannonse-finne-... [R=301,L]
RewriteRule ^?side=kategori&kategori=ukeblader_magasiner$ http://www.dinstartside.no/?side=kategori&kategori=ukeblader-og-magasiner [R=301,L]

I removed the “/?side=kategori&kategori=” part of the old url to see if there was another issue that caused the failure, but it redirected perfectly to new page.

Anyone plz.

Diseño web Mallorca’s picture

I came across this, but when i try redirect from my frontpage https://www.dereksolutions.com/es to https://www.dereksolutions.com it changes all the links and removes the language code.

I'm trying from the .htaccess file.

boinkster’s picture

I had the problem migrating to a new domain but needed to keep the services endpoints active on old domain since they were externally active. The key was including a RewriteCond for index.php:

RewriteCond %{REQUEST_URI} !^/services/active/endpoint$
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{HTTP_HOST} ^old-domain\.org$ [NC]
RewriteRule ^(.*)$ http%{ENV:protossl}://new-domain/$1 [L,R=301]