Forum Moderators: open

Message Too Old, No Replies

301 redirects and htaccess

Does the physical file have to exist?

         

Broadway

10:14 pm on Jan 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm on a widows server (IIS6/Plesk).

Via Webmaster tools I've become aware of some incoming links to my site to non-existant pages. Specially I'm talking about incoming links that contain file name problems, including misspellings. Some of these misspellings contain characters that are not allowed in file names (!#$%&'()+,-, etc..) .

When making 301 redirects in IIS 6, you create a file with the misspelled name and upload it to your server. Then you use remote desktop to access IIS where you locate the actual file and create a 301 redirect for it.

The problem I am having is that in the case of incomming links to those misspellings that contain "non-allowed" characters (and non-allowed character formats) for a file, I can't create a file to upload. Therefore I can't create a 301 redirect for that instance.

I've become aware of an add-on I can use with IIS that allows me to use an htacess-like file for redirects (I have to assume its use and nomenclature is based on the Unix model).

My question is, with the Unix htacess file and creating redirects, can you make redirects for filenames that contain non-allowed characters and formats for file names?

encyclo

1:14 am on Jan 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I assume you're referring to the ISAPI rewrite tool, which is an implementation of Apache's mod_rewrite. This does not depend on the creation of mapped files, so you are not affected by filename restrictions.

woakesd

3:13 pm on Mar 8, 2010 (gmt 0)

10+ Year Member



Another method of dealing with this is to change the default 404 custom error handler to a url (/404handler.asp for example).

If an non existant page is requested then your handler is called and passed a query string which looks like:

404;non-existant-page.asp

By examining the part after the semi colon you can decide what you want to do (301 redirect) or display a custom error page.

You can do a 301 redirect in Classic ASP using the lines:

Response.Status="301 Moved Permanently"
Response.AddHeader "Location","/real-page.asp"
Response.End

You could use a database table for looking up mispelt URLS to redirect to or just have a big SELECT CASE.

marcel

7:41 pm on Mar 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi woakesd, and welcome to WebmasterWorld!

Thanks for showing us an alternative method of rewriting/redirecting non-existant pages. Just one question, will IIS return a 404 to the requesting browser before calling the custom 404? ie. first returing a 404, and then for example a 301 for the redirect?

I haven't a test machine available at the moment to try it out, unfortunately.

Ocean10000

7:47 pm on Mar 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I can answer this one. IIS will not return the 404 status until the request ends or the headers have been forced flushed. IIS will call the custom 404, then depending on the 404 page it will return either the 404 status or what the 404 page coding tells it to return.

woakesd

9:39 pm on Mar 9, 2010 (gmt 0)

10+ Year Member



That's correct. Your error handler can overwrite the returned status. And you can use this for any of the custom error pages, or return 410 Gone if you want to have a page removed from a search engine.

I've used this on a site which had several domains and needed to remove some pages from the search engine for one domain which had leaked in, you check the host header and then do:

Response.Status="410 Gone"
Response.End

Like this you might see a blank page but as Ocean10000 says as long as the headers haven't been flushed you can do this and then output a nicely formatted Gone page before calling Response.End.