301 Redirect old site URL's in new Drupal installation - .htaccess

I'm looking to 301 redirect an URL from a old version of a site no longer being used to a new URL that has been created in fresh Drupal installation.
Old URL: /198/our-software/
New URL: /services/software-development/
In the .htaccess located in the root directory of Drupal I have added the following:
redirect 301 /198/our-software/ http://www.domain.com/services/software-development
The redirect is working to some extent, it sends the user to a url like below with a query string appended to the end of it, which results in a 404 error:
http://www.domain.com/services/software-development?q=198/our-software/
I have tried placing the redirect at both the start and end of the .htaccess file both result in a 404 page not found error.
Do I need to use a more complex redirect to get around Drupals URL rewrite?
NOTE: I'm using the Pathauto module.

Rather than edit the .htaccess directly, just install the Path Redirect module which has that exact functionality built in.
Note that the Path Redirect module is only available for Drupal 6 (as of 2/22/12)

I got it working with using "RewriteRule" instead, AND (important!) removing the leading slash in the source URL, so in your case:
RewriteRule 198/our-software/ http://www.domain.com/services/software-development [R=301,L]

Related

htaccess - redirect parent folder to file within parent folder

I'm attempting to redirect the user to a file within a folder if the user types the folder's address as a URL.
For example:
https://www.example.com/shop
should redirect to:
https://www.example.com/shop/en_GB/index.html
I've tried to do it using a htaccess file in the root with the following rule:
Redirect 301 /shop https://www.example.com/shop/en_GB/index.html
but this does not work - it adds the file URL over and over again in the address bar.
Can anyone help? Thanks.
Redirect directive matches any URI pattern that starts with the given string. Hence you're getting a redirect loop.
You should use RedirectMatch directive for this purpose that supports regex and allows you to match precise strings.
RedirectMatch 301 ^/shop/?$ /shop/en_GB/index.html
Make sure to use a new browser for your testing or clear browser cache completely.

.htaccess redirect old domain to new domain

I use from http://siteold.com/json/ in my application and can not change it.
and my new domain is http://panel.sitenew.com/json/ . how redirect my old url to new url without change in application ?
this way does not work (in siteold.com) :
RewriteEngine On
Redirect http://siteold.com/json/ http://http://panel.sitenew.com/json/
I don't think it is possible to redirect a URL to another URL. You will have to create a htaccess.txt file to the directory of the website you want to redirect, and then use this code
Redirect /siteold.com/json/ http://panel.sitenew.com/json/
This will redirect the old file path to the new file path. You cannot add http:// to the origin domain as the code doesn't work like that.
Source

301 redirect adding unnecessary query string to new url

I'm trying to set up 301 redirects from a subdomain to the main domain, but I'm running into issues when the old urls have query strings.
The new site is running PHP as aFastCGI process. I tried using the solution listed here: https://expressionengine.stackexchange.com/questions/5188/301-redirects-appending-query-string
and it works for most urls, but not when the old urls have query strings.
For example,
RewriteRule ^old-blog/title/?$ http://www.example.com/new-blog/title/ [L,R=301]
works to redirect old.example.com/old-blog/title to www.example.com/new-blog/title but I'm
having trouble with pages that include query strings. I tried using this:
RewriteRule ^Default\.aspx?/?$ http://www.example.com/new-blog/ [L,R=301]
but a url like old.example.com/default.aspx?title redirects to www.example.com/new-blog/?title instead of just www.example.com/new-blog/
Can I stop the query strings from being appended to the new urls?
Also is there a way to just do a blanket redirect of every link that ISN'T already redirected using the first method above to www.example.com/new-blog/ ?
Not sure if it matters but the new site is running ExpressionEngine and using htaccess to remove index.php from the urls, but the htaccess rules above are on the old subdomain.

Redirect directory to a subdomain

I have my domain pointed to a Rails app in Heroku, so for example, when you wanted to access some video, you would have an URL such as:
http://codigofacilito.com/video/W53XHWkbz34
We need to change that app to a subdomain, so the updated version would be:
http://videos.codigofacilito.com/video/W53XHWkbz34
What I want to know is:
Is there a way to redirect people to the new url with the subdomain videos by using the .htaccess file.
If you need this rule to only be applied to the video route, then give the following a try:
In your document root's .htaccess file, insert the following rule:
RewriteRule ^(video/.*)$ http://videos.codigofacilito.com/$1 [R=301,L,NC]
This works for me
RedirectMatch 301 ^/xxx/(.*)$ http://xxx.domain.com/$1
Using mod_alias:
Redirect permanent /video http://videos.codigofacilito.com/video
The keyword permanent causes Apache to send an HTTP status of 301 Moved Permanently instead of 302 Found.

.htaccess Redirect on a url with spaces in it

I have a link from anther website that I do not have control of http://example.com/one two three.exe
The correct URL is http://example.com/one_two_three.exe
Note the underscores instead of spaces.
I searched the internet and found this code snippet for .htaccess
# Redirect old file path to new file path
Redirect /one%20two%20three.exe http://example.com/one_two_three.exe
I added this snippet to my preexisting root .htaccess at the top of the file.
But it does not seem to work. My browser does not redirect and I get a 404 error page.
I believe that it has something to do with the spaces in the original URL but I don't know how to handle spaces in the URL.
Suggestions?
You could try a couple of things (both untested)
Redirect "/one two three.exe" http://example.com/one_two_three.exe
or use RewriteRule instead of Redirect:
RewriteRule /one\ two\ three.exe http://example.com/one_two_three.exe

Resources