homepage Welcome to WebmasterWorld Guest from 54.226.213.228
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
can i redirect aspx to html
meelosh




msg:4445318
 2:40 pm on Apr 25, 2012 (gmt 0)

Hi Guys...I am looking at re-designing and re-developing a clients older site that has .aspx extensions. The site has about 30 pages and i have not worked with that file type before and would want to redirect all to .html I will also then be moving the site i complete in html to a different host and would want to do the redirect in the htaccess file (aspx to html) . Do i need to 301 all pages or can i do it globally and what impact would this have on SEO? thanks for any help and advice.

 

g1smd




msg:4445350
 3:29 pm on Apr 25, 2012 (gmt 0)

When you move to a different host, will the domain name also change? If it does, then you can change the file extensions too.

If the domain name is staying the same, then you can and should keep the same extensions even if the pages themselves use plain HTML or are generated by a PHP script.

There's very simple settings to enable PHP to scan .aspx files for PHP code (AddHandler etc).

The files on the server can have the .html extension while using .aspx in the URLs for those pages. That's a one-line simple rewrite using a RewriteRule.

However, if you are convinced you need to change the extensions, from aspx to something else, then consider completely removing the extensions from the URLs by going extensionless. The physical files on the server will still need an extension though.

If you merely change the extensions from aspx to html, I forsee you posting here in a couple of years time asking how to change from .html to .php extensions. Avoid all of that and go extensionless now.

The two RewriteRules needed for this (one configured as a redirect, the other as a rewrite) are beautifully simple.


There's three factors to consider here:
- what technology generates the page: "plain html in a text file" vs. "a scripting language such as php",
- what extension do the actual files "here" inside the server have,
- what do you want the URLs used "out there" on the web to look like?

You can configure any combination you want. That's what URL rewriting is for.

meelosh




msg:4445370
 3:53 pm on Apr 25, 2012 (gmt 0)

thanks for that g1smd

The domain name is going to stay the same when we move to another host. The pages are well indexed so It be best to keep the extensions as you say. How do i develop the pages in html and have them keep their aspx extensions...pls help. I want to make sure that the very least amount of disruption takes place with regards to seo and offcourse still have all inbound links working that link to the aspx pages but the site will be developed in html. Can you pls advise me on how to proceed with this...thanks for the help

meelosh




msg:4445379
 3:58 pm on Apr 25, 2012 (gmt 0)

thanks just saw the last bit now..

technology will be plain html pages
so the actual files will be html
the urls to be generated for the search engines and web should have aspx file extensions instead of html as the originally indexed site was indexed as aspx.

How do i do this? thanks for the help

g1smd




msg:4445386
 4:06 pm on Apr 25, 2012 (gmt 0)

The simplest way is to save the pages on the server using
filename.aspx and they will just work (you might need to add an AddType .aspx text/html {check Apache site for exact syntax} directive in the .htaccess file).

The navigation links on those pages should point to
href="/otherpagename.aspx" etc.

The root page should be saved as
default.aspx and then linked in the site navigation as href="/" not using the actual file name.

You will also need to add this code to the
.htaccess file (assuming you use Apache hosting):

# Directory Index
DirectoryIndex default.aspx

# Redirect default.aspx requests to URL ending / on www
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*default\.aspx\ HTTP
RewriteRule ^(([^/]+/)*)default\.aspx$ http://www.example.com/$1? [R=301,L]

# Redirect non-canonical requests to www
[code]RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]


That's two redirects.

----

If you want to add one layer of complexity then save the pages using the
.html extension.

The navigation links on those pages should point to
href="/otherpagename.aspx" etc.

The root page should be saved as
index.html and then linked in the site navigation as href="/" not using the actual file name.

To make it all work add this code to the
.htaccess file:

# Directory Index
DirectoryIndex index.html

# Redirect default.aspx and index.html requests to URL ending / on www
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(default|index)\.(aspx|html?)\ HTTP
RewriteRule ^(([^/]+/)*)(default|index)\.(aspx|html?)$ http://www.example.com/$1? [R=301,L]


# Redirect .html URL requests to equivalent .aspx URLs on www
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*[^/.]+\.html\ HTTP
RewriteRule ^(([^/]+/)*[^/.]+)\.html$ http://www.example.com/$1.aspx [R=301,L]


# Redirect non-canonical requests to www
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]


# Internally rewrite .aspx URL requests to .html file
RewriteRule ^(([^/]+/)*[^/.]+)\.aspx$ /$1.html [L]

That's three redirects and one rewrite. All use a RewriteRule.

----

URLs are used "out there" on the web. Files are used "here" inside the server. They are not at all the same thing. They are merely "related" by the actions of the server and its configuration.



Edited as per post below.

[edited by: g1smd at 4:52 pm (utc) on Apr 25, 2012]

meelosh




msg:4445422
 4:40 pm on Apr 25, 2012 (gmt 0)

wow thank you so much for the help....and this will not disrupt anything with google as the pages will still be seen in their originally indexed url and file extension.
This site is running on this type of file structure www.mysite.com/Pages/default.aspx
Should i leave it running from a "pages" directory for seo or can i do away with this directory and redirect it back to "/". Would i substitue index with default in your code? Sorry for the questions...i have done some simple redirects before but this is a bit...well allot above me and i want to get it right...appreciate your help

g1smd




msg:4445439
 4:50 pm on Apr 25, 2012 (gmt 0)

Yes.
index\.aspx should be default\.aspx in the code.

Edited the original post for all the required fixes.

I'd not mess with the /Pages/ folder part at this time. You've already got enough work to be getting on with, without that.

meelosh




msg:4445471
 5:26 pm on Apr 25, 2012 (gmt 0)

thank you so much for the help...i did not know if it could be done without a google headache...appreciate it thank you

g1smd




msg:4445480
 5:46 pm on Apr 25, 2012 (gmt 0)

I'd estimate this thread saved you more than a week of research, coding and bug fixing. :)

Long term I would aim for extensionless URLs. Staying with .aspx URLs for now is the least disruptive as far as Google goes.

Google deals with URLs. It matters not one bit what the filename of the file on the actual server hard drive is called. If the URLs are the same, they will have no idea that something inside the server changed.

lucy24




msg:4445642
 9:49 pm on Apr 25, 2012 (gmt 0)

Is the "aspx = html" business going to cause trouble with older browsers? I remember MSIE 6 having fits when I accidentally saved some graphics files with the wrong extension.

g1smd




msg:4445651
 9:58 pm on Apr 25, 2012 (gmt 0)

There shouldn't be an issue as long as the content is properly returned as "text/html".

Extensions for HTML pages shouldn't make any difference.

Images - that's entirely another matter. And IE has had many quirks with that.

meelosh




msg:4445818
 6:06 am on Apr 26, 2012 (gmt 0)

thanks again g1smd this has openend my eyes that you can develop on most any environment and then serve up the url as you pls to keep the status quo. I will be implementing this in the next few weeks and hopefully all goes well....if not hopefully i can pick your brain somemore..appreciate it

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved