How to set up the 301 redirect for IIS Server? - seo

i am getting canonical issue in my web site. the error is as follows:
The page with URL "http://dynamicsexchange.com/images/CRMcommunity_supersources_withspaces.jpg" can also be accessed by using URL "http://www.dynamicsexchange.com/images/CRMcommunity_supersources_withspaces.jpg".
all errors i got are related to non-www and www so, please tell me how to set www.mysite.com for my site.
Thanks and Regards
M Prasad Reddy

If it's asp 2 and above you can implement it in 2 ways:
1) ASP.NET: Redirecting with ASP.NET and IIS
you can implement 301 redirects using ISAPI Rewriting modules, products like UrlRewriter.NET which is discussed in Chapter 3, "Provocative SE-Friendly URLs," of the book, Professional Search Engine Optimization with ASP.NET: A Developer's Guide to SEO, or from within your ASP.NET code by setting the appropriate header data.
When using ISAPI_Rewrite, redirecting is implemented similarly to URL rewriting, except that you specify a redirection status code as a parameter.
Example :
The following rule does a 301 redirect to Catalog.aspx when the initial request is for Catalog.html:
301 Redirect Catalog.html to
Catalog.aspx RewriteRule
^/Catalog.html$
http://seoasp/Catalog.aspx [RP]
2) In Code
If you want to implement the redirect yourself, you need to manipulate the response headers using the Response object provided by your current HttpContext object. Here's how to 301 redirect Catalog.html to Catalog.aspx yourself:
if (context.Request.Path == "/Catalog.html")
{
context.Response.Status = "301 Moved Permanently";
context.Response.AddHeader("Location", "http://www.example.com/Catalog.aspx");
}
Explanation: The first URL should be a relative path to the old URL and the second one should be an absolute path to the new URL.

Related

How to redirect an URL to another (.htacces)

Friends, I need to redirect an URL (which doen't exist in the blog anymore) to another one in the same blog. How could I do this with the help of .htaccess?
The problem is that we have a printed QR-Code which leads people to this old URL which was in our old blog. We have another one now, using the same subdomain. Any idea?
From
https://blog.mywebsite.com.br/2020/08/28/planner-para-que-serve-e-como-usar/
To
https://blog.mywebsite.com.br/planner-para-que-serve-e-como-usar/
I have tried this so far:
Redirect "https://blog.volarepaper.com.br/2020/08/28/planner-para-que-serve-e-como-usar/"
"https://blog.volarepaper.com.br/planner-para-que-serve-e-como-usar/"
and this as well:
Redirect "https://blog.volarepaper.com.br/2020/08/28/planner-para-que-serve-e-como-usar/"
"https://blog.volarepaper.com.br/planner-para-que-serve-e-como-usar/"
You can not use full URL in the pattern of Redirect . You can only use URL path :
Redirect 301 /2020/08/28/planner-para-que-serve-e-como-usar/ https://blog.volarepaper.com.br/planner-para-que-serve-e-como-usar/

Redirect a specific single web page from one domain to a specific web page under another domain

How do I get the following redirect to work?
The old address contains URL parameters:
olddomain.com/Index.asp?CategoryID=2379&ArticleID=6592
And needed to redirect to a regular URL under the new domain:
newdomain.com/example-page
Can I do it via mod_rewrite on on my .htaccess file? what is the correct command for this redirection?
I will need to do that for each page under the old domain (the target URL under the new domain will be different for each page)
Actually nothing, the only solution I found was to redirect the entire domain to the new domain, without redirecting each page to it's target.

301 rdirect for custom URL

I have a custom made image gallery site that I converted to WordPress, this site have few thousands link like this
http://www.example.net/Gallery?cmd=viewCarGallery&carID=13&pgID=1
http://www.example.net/Gallery?cmd=viewCarGallery&carID=9&pgID=1
All link is now converted to wordpress and now I am facing problem redirect them, I tried to using like this
Redirect 301 /Gallery?cmd=viewCarGallery&carID=9&pgID=1 http://www.example.net/gallery/gallery_ID
Please help me how can I redirect this kind of URL.
A permanent 301 redirect in your .htaccess file lets search engines and others know that an old link has been replaced by a new one. It's the recommended method for directing traffic from an existing page.I added below codes in my .htaccess file.
Redirect 301 /oldfile.htm /newfile.htm
I think what you need is mod rewrite. Take a look here http://www.askapache.com/htaccess/modrewrite-tips-tricks.html
It looks like a similar question https://superuser.com/questions/155139/htaccess-301-redirect-with-regular-expressions

Understanding difference between redirect and rewrite .htaccess

I'd like to understand the difference between redirecting and rewriting a URL using .htaccess.
So here's an example: Say I have a link like www.abc.com/ index.php?page=product_types&cat=88 (call this the "original" url)
But when the user types in abc.com/shoes (let's call this the "desired" url), they need to see the contents of the above link. To accomplish this, I would do this:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)shoes(.*)$ index.php?page=product_types&cat=88
Nothing wrong with this code and it does the trick. However, if I type in the original url in the address bar, the content comes up, but the url does not change. So it remains as www.abc.com/index.php?page=product_types&cat=88
But what if I wanted the desired url (/shoes) to show up in the address bar if I typed in www.abc.com/ index.php?page=product_types&cat=88? How would this be accomplished using .htaccess? Am I running into a potential loop?
Some of the explanation can be found here: https://stackoverflow.com/a/11711948/851273
The gist is that a rewrite happens solely on the server, the client (browser) is blind to it. The browser sends a request and gets content, it is none the wiser to what happened on the server in order to serve the request.
A redirect is a server response to a request, that tells the client (browser) to submit a new request. The browser asks for a url, this url is what's in the location bar, the server gets that request and responds with a redirect, the browser gets the response and loads the URL in the server's response. The URL in the location bar is now the new URL and the browser sends a request for the new URL.
Simply rewriting internally on the server does absolutely nothing to URLs in the wild. If google or reddit or whatever site has a link to www.abc.com/index.php?page=product_types&cat=88, your internal server rewrite rule does absolutely nothing to that, nor to anyone who clicks on that link, or any client that happens to request that URL for any reason whatsoever. All the rewrite rule does is internally change something that contains shoes to /index.php?page=product_types&cat=88 within the server.
If you want make it so a request is made for the index.php page with all of the query strings, you can tell the client (browser) to redirect to the nicer looking URL. You need to be careful because rewrite rules loop and your redirect will be internally rewritten which will cause a redirect which will be internally rewritten, etc.. causing a loop and will throw a 500 Server Error. So you can match specifically to the request itself:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?page=product_types&cat=88
RewriteRule ^/?index.php$ /shoes [L,R=301]
This should only be used to make it so links in the wild get pointed to the right place. You must ensure that your content is generating the correct links. That means everything on your site is using the /shoes link instead of the /index.php?page=product_types&cat=88 link.

Preventing a double redirect with htaccess

I'm trying to create a redirect in-between page of sorts, because the URL that I'm redirecting TO includes more information than the URL I'm redirecting FROM. I'm using a short domain (hrci.me) with an htaccess file to redirect to the full domain (currently reachchallenges.infectionist.com). An example would be:
hrci.me/ch123
The path, ch123, includes the identifier that lets me know it's a challenge link (ch), and the 123 is the challenge ID. Each challenge has a title that I like to append to the end of the URL for SEO purposes. This example URL would redirect to:
reachchallenges.infectionist.com/challenge/123/Challenge+Title
The "Challenge+Title" part is stored in the database and needs to be retrieved by the challenge id, so I wrote a simple PHP script that does just that and then handles the redirect itself. My htaccess rule looks like this:
RewriteRule ^ch([0-9]{1,4})(/)?$ redirhandler.php?chid=$1 [L]
So the request to /ch123 should redirect to redirhandler.php?chid=123, which would get the title then redirect to the other domain at /challenge/123/Challenge+Title. The problem is, the short domain is set up to forward all incoming requests to the long domain, maintaining the original path (so hrci.me/something would redirect to reachchallenges.infectionist.com/something), and I'm finding that after the htaccess handles the rewrite to redirhandler.php, it then redirects that to reachchallenges.infectionist.com/redirhandler.php...
Basically, I need it to ignore any further redirects if the path is redirhandler.php, allowing the php script to handle the rest o the redirect. I'm thinking a RewriteCond is how I might do this, but I can't figure it out.
It sounds like your rule that forwards all incoming requests to the long domain is higher up in the .htaccess file than the more specific rule for /ch* requests. Try putting the more specific rule before the more general one.