How can I mask so all instances of www.oldsite.com are replaced with www.newsite.com
example:
I'd like to replace:
http://www.oldsite.com/home/b.jsp?id=9912&ln=115-991632
with www.newsite.com/home/b.jsp?id=9912&ln=115-991632
You can do this in Apache with the Redirect directive:
<VirtualHost *:80>
ServerName www.oldsite.com
Redirect permanent /home/ http://www.newsite.com/home/
</VirtualHost>
Well, if you only want to replace that page, you can create a .htaccess file with this content:
Redirect 301 /b.jsp?id=9912&ln=115-991632 http://www.newsite.com/home/b.jsp?id=9912&ln=115-991632
That's all I can think now. You should upload it to your /home directory.
If you want to do at the application level, just print a location header:
#!/bin/bash
echo 'Location: http://www.newsite.com'
To make it even better, you can place that cgi script at "home" (replace the directory with a script) and use the $PATH_INFO variable to do the correct thing
#!/bin/bash
echo 'Location: http://www.newsite.com/$PATH_INFO'
Related
Is there any way of making a 301 redirect from:
/#done
to
/bin
I currently have this code situated in my .htaccess file:
Redirect 301 /#done /bin
But it does not redirect because of the illogical placement of the #, within the statement, is there any way to overcome this? With the resulting URL still redirecting from the address of example.com/#done?
Thanks
The # character is a reserved character in URLs according to RFC3986.
You could try whether it helps to use the character's encoded representation %40 instead.
Update
You could create the folder #done at the proper place of the webserver and put an index.php file in it. This will redirect all requests from /#done to /bin.
<?php
header('HTTP/1.1 301 Moved Permanently');
header("Location: /bin");
header("Connection: close");
?>
htaccess works without problem when i`m using english characters.
but when I use not english characters, it cant redirect and shows :
Not Found
The requested URL
these are my sample code. I have tasted it different types but nono of them works :
Redirect 301 "/مقاله-انواع-دسته-بندی-برج-های-خنک-کننده" /destination
Redirect 301 "/%D9%85%D9%82%D8%A7%D9%84%D9%87-%D8%A7%D9%86%D9%88%D8%A7%D8%B9-%D8%AF%D8%B3%D8%AA%D9%87-%D8%A8%D9%86%D8%AF%DB%8C-%D8%A8%D8%B1%D8%AC-%D9%87%D8%A7%DB%8C-%D8%AE%D9%86%DA%A9-%DA%A9%D9%86%D9%86%D8%AF%D9%87" /destination
Add the following line in your Apache configuration file:
AddDefaultCharset UTF-8
then restart your Apache server. After this, you may use your htaccess file which contains redirects with UTF-8 characters, and they should now be recognized. You should make sure that you save your htaccess file in a format which supports UTF-8.
You can use this rule in your site root .htaccess:
RewriteEngine On
RewriteRule ^مقاله-انواع-دسته-بندی-برج-های-خنک-کننده/?$ /destination [L,B,R=301]
I need to detect subdomain in cakephp. I assume this can be done through .htaccess rules but I'm a newbie and not much knowledge with .htaccess
You dont need to use .htaccess I found the solution using regex.
$url = "abc.yourdomain.com";
preg_match('/^(?:www\.)?(?:(.+)\.)?(.+\..+)$/i', $url, $matches);
$subdomain = empty($matches[1])? '' : $matches[1];
you will get abc in the subdomain, for www.yourdomain.com or yourdomain.com that will be empty
I do not understand htaccess fully so I need help solving this. I need to redirect users from the directory www.example.com/es and www.example.com/en to the subdirectory www.example.com/old/es and www.example.com/old/en.
Add this in the htaccess file in your document root:
RedirectMatch 301 ^/(en|es)(/.*)?$ /old/$1$2
If you only want to redirect /en and /es, and not /en/foo or /es/something/else then remove the $2 bit from the end.
it's my first question here :)
I got a problem for redirecting URL:
I have old URL like www.domain.com/cgi-bin/category.cgi?type=...
And try to redirect them to www.domain.com on the htaccess
but I still have 404 error...
This is my rule :
RewriteRule ^cgi-bin/(.*)$ http://www.domain.com [R=301,L]
I verified if there are something in the conf about cgi-bin but nothing.
I did a test with "cgi-bin2" and it works...
So what can i do ?
I don't know where you problem come from but why don't you try to write a perl script which will redirect to your base domain url ?
(it can work if you have, for example, just few cgi files previously used).
In your example it seems you want to redirect "category.cgi".
so, in our case, write a "category.cgi" file in your "cgi-bin" folder and write this code inside it :
#!/usr/bin/perl
#
# fixedredir.cgi
use strict;
use warnings;
my $URL = "http://www.yourdomain.com/";
print "Status: 301 Moved\nLocation: $URL\n\n"
Hope it help !