Converting files from .html to .php or editing .htaccess file
-
Good day all,
I have a bunch of files that are .html and I want to add some .php to them.
It seems my 2 options are
- Convert .html to .php and 301 redirect
or
- add this line of code to my .htaccess file and keep all files that are .html as .html
AddType application/x-httpd-php .html
My gut is that the 2nd way is better so as not alter any SEO rankings, but wanted to see if anybody had any experience with this line of code in their .htaccess file as definitely don't wan to mess up my entire site
Thanks for any help!
John
-
Hi John
The first line removes the extension
The second line adds them back in a specific order IE you want PHP to execute first.
If you got it going that is what counts.
Good luck,
Don
-
Thanks so much for this Don.. this is what I added that seemed to work for my server
AddHandler application/x-httpd-php .html .htm
As the AddType caused errors but doing some further research I found the above code.
I wonder if what you propose would accomplish what I did?
Thanks and all the best,
John
-
Hi John,
If the URL's are well indexed and doing well, you "may" not want to change the url. To simply add the ability to run php first you can do it very easily with just what you thought, .htaccess
In fact when I took over as webmaster on my corporate site which was indexed very well I had to do just that.
Add this to your .htaccess file:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html -
If you really want to go this route, add this to your site .htaccess
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.html [NC,L]So domain.com/file will access file.html
Again, the caveat is there is a short term SEO hit for doing this. Long term, you should be fine.
-
This is a sweet idea.. any tutorial on this? How does it effect existing links directed at the .html and .php pages?
Thanks Keri!
-
Have you considered just rewriting your URLs so they don't use extensions at all? That way, when you use a different technology, you don't need to rewrite your URLs once again. If you look at SEOmoz, you see they don't use .php or .html as extensions, but instead have no extensions.
-
I did option 1 on one of my websites some time ago and works fine, rankings are the same. Takes about 2 moth to get the same visits on all the links again.
-
We use the AddType function all the time when updating websites. It's far easier to do that that to recreate everything and redirect it.
It allows all of your internal navigation to remain as is and it keeps all of your inbound links from becoming redirected links. Also, remember that it has been announced that 301 redirected links lose value over time so this is another reason to not do it the hard way.
-
Just make sure that you don't redirect all HTML files. I suspect that either way is equal. What you are telling in either case i
"Hi Google we have moved but don't worry we have moved here"
-
I would pick #2, where you process .html files with PHP. Changing URLs involves taking a temporary SEO hit and I would not recommend doing it.
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
Robots.txt allows wp-admin/admin-ajax.php
Hello, Mozzers!
Technical SEO | | AndyKubrin
I noticed something peculiar in the robots.txt used by one of my clients: Allow: /wp-admin/admin-ajax.php What would be the purpose of allowing a search engine to crawl this file?
Is it OK? Should I do something about it?
Everything else on /wp-admin/ is disallowed.
Thanks in advance for your help.
-AK:2 -
Only Images Show Up in Log Files
Has anyone ever seen a log file analysis return only images and no actual page URLs?
Technical SEO | | LoganRay0 -
301 redirect syntax for htaccess
I'm working on some htaccess redirects for a few stray pages and have come across a few different varieties of 301s that are confusing me a bit....Most sources suggest: Redirect 301 /pageA.html http://www.site.com/pageB.html or using some combination of: RewriteRule + RewriteCond + RegEx I've also found examples of: RedirectPermanent /pageA.html http://www.site.com/pageB.html I'm confused because our current htaccess file has quite a few (working) redirects that look like this: Redirect permanent /pageA.html http://www.site.com/pageB.html This syntax seems to work, but I'm yet to find another Redirect permanent in the wild, only examples of Redirect 301 or RedirectPermanent Is there any difference between these? Would I benefit at all from replacing Redirect permanent with Redirect 301?
Technical SEO | | SamKlep1 -
Can someone interpret this entry in my htaccess file into english so that I can understand?
There are a number of entries in my htaccess and I'd like to understand what they are doing so that I can understand if they need to be there or not. So, can someone tell me what this says...in plain english? RewriteCond %{HTTP_HOST} ^legacytravel.com$ [OR]
Technical SEO | | cathibanks
RewriteCond %{HTTP_HOST} ^www.legacytravel.com$
RewriteRule ^carrollton-travel-agent$ "http://www.legacytravel.com/carrollton-travel-agent" [R=301,L] Thank you a million times in advance.0 -
Help creating a 301 redirect in my htaccess file
Hi Guys, I'm trying to build a 301 file with the file requirements: It should be visible only for Google and other Search Engine Agents. It will have a few direct redirects. A few URL must be dynamic redirect. For example each page the starts with olddomain.com/category and is not in the list of of direct redirects should be redirect for newdomain.com/category Here is my start point: #301 Starts here Set the agents RewriteEngine On
Technical SEO | | Felip3
RewriteCond %{HTTP_USER_AGENT} Googlebot [OR]
RewriteCond %{HTTP_USER_AGENT} msnbot [OR]
RewriteCond %{HTTP_USER_AGENT} Slurp Make the direct redirect. Redirect 301 /category/sub1 http://www.newdomain.com/category/sub1
Redirect 301 /category/sub2 http://www.newdomain.com/category/sub2 Redirect everything else Redirect 301 /category/* http://www.newdomain.com/category #End of my 301 Will that work how I want? is there anything wrong?0 -
Htaccess - multiple matches by error
Hi all, I stumbled upon an issue on my site. We have a video section: www.holdnyt.dk/video htaccess rule: RewriteCond %{REQUEST_FILENAME} !-f
Technical SEO | | rasmusbang
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^video index.php?area=video [L,QSA] Problem is that these URLs give the same content:
www.holdnyt.dk/anystring/video
www.holdnyt.dk/whatsoever/video Any one with a take on whats wrong with the htaccess line? -Rasmus0 -
My .htaccess has changed, what do i do to avoid it again...?
Hello Today i notice that our site did not auto changed from without www to with, when i checked the .htaccess file i notice # in-front of each line and i know we did not insert it in there, after i removed it it worked fine. The only changes that we did recently was to a mobile version to the site but the call to autodirect is in a JS and not in the .htaccess, could it be the server..? is there any way that anything else might cause this...? The site is HTML and WP could it be because of that...? Thank's Simo
Technical SEO | | Yonnir0 -
301 redirect .htaccess problem
Can anyone explain to me why this doesn't work? Redirect 301 /category/diamond-pendants/nstart/1/start/(.*) http://www.povada.com/category/pendants/nstart/1/start/$1 Im trying to replace everything after /start/ and insert it into the new url. Thanks in advance.
Technical SEO | | 13375auc30