Jump to content

302 redirect from .htm to .php?


kurt.santo

Recommended Posts

Converted a site from .htm files to .php files and put them online. Just wondered if there is anything I need to do now with regard to search engines. Would I need to redirect via 302-.htacess? Have been told that I should have put sth in .htaccess to make have .php page look like .htm, but not sure if that is the way forward (also did not work properly). Does anyone have an idea? The website owner did not spend much time and effort on SEO, but I do want to make sure we do the conversion in the best possible way. Site is online since two days, guess I should have thought a bit more about it beforehand...Kurt

Link to comment
Share on other sites

The extension makes no difference, as far as anyone can tell, to sites SE rankings. You can use the Apache mod_rewrite to make the .htm URLs redirect to the PHP pages. But... isn't your site structured differently now that you have server technologies anyway?

Link to comment
Share on other sites

The extension makes no difference, as far as anyone can tell, to sites SE rankings. You can use the Apache mod_rewrite to make the .htm URLs redirect to the PHP pages. But... isn't your site structured differently now that you have server technologies anyway?
There are some more files (the include files etc), but main files are named/stored exactly as it was before. THe only difference is that they are now .php files instead of .htm and the content is generated from include files.I have read that you should never change the structure of a website with regard to SEO and now as this site is live I found that they say (on SEO forum) that you should not change to .php, but enable the .htm to act as .php. I find this all kind of confusing, do not really get it why the search engines won't find it anyway when they crawl the web (or would I need to manually submit the change?).How would I do the mod_rewrite? In .htaccess I assume?Kurt
Link to comment
Share on other sites

For best SEO results, you shouldn't use any sort of extension in your URL i.e. use folders instead of files.Not only does this have the potential of increasing SEO (though if you ask me, search engines don't make any distinction between a PHP page, an HTML page or a folder - they only care about the MIME type of the received document), but it also increases usability for users.Instead of having to remember

example.com/page.html

and

example.com/page-in-a-category.html

they'll have to type the more intuitive

example.com/page/

and

example.com/category/page/

It also gives you technology independance. Feel like tomorrow you'll migrate to XHTML or ASP.NET, or JSP? Or just try out PHP6 thanks to your host that happens to somehow allow you to use it with .php6 as an extension? No problem. Replace the files, make whatever is needed to redirect to the new files instead of the old ones, and you're set. The URLs will remain, and thus SEO would be intact.And yes. You'd do the mod_rewrite in an .htaccess file, provided your host allows you to.

Link to comment
Share on other sites

For best SEO results, you shouldn't use any sort of extension in your URL i.e. use folders instead of files.Not only does this have the potential of increasing SEO (though if you ask me, search engines don't make any distinction between a PHP page, an HTML page or a folder - they only care about the MIME type of the received document), but it also increases usability for users.Instead of having to remember
example.com/page.html

and

example.com/page-in-a-category.html

they'll have to type the more intuitive

example.com/page/

and

example.com/category/page/

It also gives you technology independance. Feel like tomorrow you'll migrate to XHTML or ASP.NET, or JSP? Or just try out PHP6 thanks to your host that happens to somehow allow you to use it with .php6 as an extension? No problem. Replace the files, make whatever is needed to redirect to the new files instead of the old ones, and you're set. The URLs will remain, and thus SEO would be intact.And yes. You'd do the mod_rewrite in an .htaccess file, provided your host allows you to.

Sounds great! Would you still have the .php or .htm ending in nav bar file listing or don't you do it there either when using mod_rewrite? Do you think its a pain that the site is already out and I did not do this from the start? I get quite nervous when I read the posts in some forums about SEO...Kurt
Link to comment
Share on other sites

Sounds great! Would you still have the .php or .htm ending in nav bar file listing or don't you do it there either when using mod_rewrite? Do you think its a pain that the site is already out and I did not do this from the start? I get quite nervous when I read the posts in some forums about SEO...Kurt
No. You'll have to update the links themselves too, so that all links use the new URLs. The UA should never have to see any extension.mod_rewrite performs rewriting of URLs as they are received by the server. It's your responsibility to provide URLs that mod_rewrite could translate properly i.e., you must give the URL
example.com/page/

which mod_rewrite could then translate to

example.com/page.html

As for the SEO part. Don't get that nervous... even if your SEO rank starts to fall, it will shortly be regained. It's just that Google's cache would need to be refreshed, and during a partial refresh (where only the most visited pages of the site are updated), your SEO rank may suffer for a while, until the rest of your visited pages get recrawled.I'm no SEO expert, but I know for sure that a SEO rank is not a constant. A site can always change its ranking (well... unless it's manually banned because of too large keyword density maybe), so whatever happens, don't worry, as you can always change it for the better.

Link to comment
Share on other sites

Cheers, will have a go on this...Kurt
Boen_robot,This mod_rewrite is quite complicated. Read through lots of sites, but cannot find exactly what I am after (just leaving away the .file-extension bit in a url). Would I need to write a rule for each file then? Hoped I could find a general rule, that translates all pages automatically (named folders and files accordingly). Also, what would I do when the user puts ?lang=de onto the querystring? Can that be rewritten as well?In addition: Found the following to link any request for an .htm page to the .php equivalent (for different project): When uploading the .htaccess it redirects to .php, but gives error 404 (although page exists)?Options +FollowSymlinksRewriteEngine onRewriteRule ^(.+)\.htm$ http://www.jalp.co.uk/$1.php [r=301,nc]Could you explain why that is? Also, can you recommend any website for background info about mod_rewrite? The sites are found are either not useful or too complex for my brains;-)KurtReason for edit: Just found that the given rewrite rule works on different live server. Tried again on problematic server without first line (read this might cause problems), but still not working properly). Actually found the solution to "extract" the file extension bit with:Options +FollowSymlinksRewriteEngine OnRewriteBase /RewriteCond %{REQUEST_FILENAME}.php -fRewriteRule (.*) $1\.php [L]Still, how would I do that if I wanted to change the file name also?
Link to comment
Share on other sites

Boen_robot,This mod_rewrite is quite complicated. Read through lots of sites, but cannot find exactly what I am after (just leaving away the .file-extension bit in a url). Would I need to write a rule for each file then? Hoped I could find a general rule, that translates all pages automatically (named folders and files accordingly). Also, what would I do when the user puts ?lang=de onto the querystring? Can that be rewritten as well?In addition: Found the following to link any request for an .htm page to the .php equivalent (for different project): When uploading the .htaccess it redirects to .php, but gives error 404 (although page exists)?Options +FollowSymlinksRewriteEngine onRewriteRule ^(.+)\.htm$ http://www.jalp.co.uk/$1.php [r=301,nc]Could you explain why that is? Also, can you recommend any website for background info about mod_rewrite? The sites are found are either not useful or too complex for my brains;-)KurtReason for edit: Just found that the given rewrite rule works on different live server. Tried again on problematic server without first line (read this might cause problems), but still not working properly). Actually found the solution to "extract" the file extension bit with:Options +FollowSymlinksRewriteEngine OnRewriteBase /RewriteCond %{REQUEST_FILENAME}.php -fRewriteRule (.*) $1\.php [L]Still, how would I do that if I wanted to change the file name also?
Yep. mod_rewrite could become quite complex and can give you nightmares if you're not careful.Do you know regular expressions already? It shouldn't be that difficult for you to grasp how mod_rewrite works if you do. If you don't though, thats when things can get ugly. Learn regular expressions first. There are tons of tutorials on the net. Search for "regex tutorial" or "regular expressions tutorial" and you'll see.You might find it easy(er) if you just redirect all of your input to a single page that selects the file for you. This tutorial of mine shows how to do that with mod_rewrite. Within PHP, you may easily use something like:
include $_GET['uri'] . '.php';

if it's just about removing the extensions.

Link to comment
Share on other sites

Yep. mod_rewrite could become quite complex and can give you nightmares if you're not careful.Do you know regular expressions already? It shouldn't be that difficult for you to grasp how mod_rewrite works if you do. If you don't though, thats when things can get ugly. Learn regular expressions first. There are tons of tutorials on the net. Search for "regex tutorial" or "regular expressions tutorial" and you'll see.You might find it easy(er) if you just redirect all of your input to a single page that selects the file for you. This tutorial of mine shows how to do that with mod_rewrite. Within PHP, you may easily use something like:
include $_GET['uri'] . '.php';

if it's just about removing the extensions.

Will have a go with your tutorial right now. Think I also need some more info about reg expressions...Still, do know why the following entry in .thaccess might not have worked on different domain/server (obviously the domain name was replaced)? As I said it did the job to sent any .htm request to the appropriate .php. It was just saying that the page cannot be displayed (althought it exists).Options +FollowSymlinksRewriteEngine onRewriteRule ^(.+)\.htm$ http://www.jalp.co.uk/$1.php [r=301,nc]Kurt
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...