So a developer updated design and changed my pure html site that has been around for a few years to .php. After seeing this, I let him know that I would prefer my site to appear as .html instead of .php for seo reasons (since all of the pages and incoming links are indexed as .html) as well as personal preference. He left both all of the old html files and created corresponding php files with new content on the ftp. the htaccess file he created looks like this: Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} ^domain\.net RewriteRule ^(.*)$ http://www\.domain\.net/$1 [R=permanent,L] RewriteRule ^(.*)\.html$ $1.php [nc] 1. I cant figure out how the heck to 301 redirect an existing url to a new one I tried: Redirect 301 /oldpage.html http://www.example.com/newpage.html and Redirect 301 /oldpage.php http://www.example.com/newpage.php and neither of them work (I tested each of them below the htaccess code) 2. Some of his code looks similar to the one used to redirect an OLD site to a NEW site which scares me for seo reasons since its still the same site - should I be concerned the way the htaccess was coded? Any help/code would be GREATLY appreciated! Thanks!
I am no mod_rewrite pro but use html flat files successfully since 11+ years with a few php files if I understand your above mod_rewrite then if you want all back to .html just remove ALL your above lines UNLESS every single page has a modified CONTENT even if in html files you need a SSI included - you can SSI via php without changing your file extensions, just add handlers to your apache config OR to your .htaccess below 2 lines is what I use since years to SSI text via php into html files ( to include footer text, adsensem RSS feeds, etc - just anything in php AddType application/x-httpd-php .html .htm AddHandler application/x-httpd-php .html .htm i have it in my server config - but many years earlier in my .htaccess above works on apache2.2 with php5 there is absolutely no reason to change an old established html flat file site into php unless you really made all pages dynamic with lots of dynamic content. changing file extensions makes ALL existing links 404 and you'll never get them back in a lifetime. changing paths / URLs is divorce from SE and customers! = expensive.
Thanks Hans! I'm completely new to php and server management so im learning as i go. I replaced all of my html files with renamed them to php files and saved locally. (I renamed the .php extentions to .html offline and then dragged them onto ftp) So right now as of this post I have file.html and file.php on the server that are identical in code. I replaced the htaccess with the 2 lines of code, but all that displays now are the body content (no navigation, footers, etc.). How can I get it to call the php stuff in the html files?
Actually, that must have been when i deleted the htacess. After replacing it with the 2 lines the browser wont browse to the pages, but instead asks me what program that I want to use to open the file (url)
the 2 lines are in addition to your regular .htaccess myself I have it in the default apache server config file. if you have html files and need them all parsed by PHP engine and get errors as you mention, then you have to google using EXACT versions of your apache/php to find exact lines to be included. if you have NO server but hosting account, then your host may have excluded overriding using the 2 lines. you then may have to ask your support for help changing the server config if they agree. you also may have to DISable server parsing for OTHER scripting such as perl when moving to PHP. you mention "... new to php and server management ... " means you run your own dedicated server ? if so then you place the lines in your apache config rather than into .htaccess. you also never mentioned what versions you have apache 1.2 or 2.2, etc depending on exact versions of apache and php you need to adapt. you also may need to adpapt your php.ini file according to your SSI needs. for that reason you better start slowly and easy. if your site was running fine before on HTML files, think twice before you make things and life for you more complicated. success is within the ease of content publishing leaving you resources to CREATE. some of the worlds largest traffic sites still are simple and straight forward in design.
Good point. I learned that it is taking a couple of hours for changes to my .htaccess to take. Right now I converted everything back to .html and the basic 301 redirect finally worked, it just took a couple of hours. After my rankings get back, I might ease back into it and experiment with the php and htaccess file some more just so i can learn. Thanks for the feedback.
.htaccess is effective instntly - ALWAYS but 2 points of course: 1. make sure your browser cache is empty and the browser actually loads the page from site NOT form cache adn much more important and complex to understand: let's say your .htaccess changed is in your site root / /.htaccess and you - your browser - is in site toor /subfolder/suringhere.html if you stay in that subfolder with your browser and make changes in /.htaccess may ( in my earlier cases ) NOT be loaded UNTIL you go back ONE times into the higher / level of your site. as long as you stay in subfolder/sub/subfoder .. you never load the changed /.htaccess again and thusly always experience unchanged .htaccess behavior only a NEW site visitor arriving at any level of your site automatically will load the .htaccess - while those already being on your site on sub-levels may continue old behavior complex may be but that is what i experienced earlier a few times and it may made sense to me when I experienced above behavior years ago. .htaccess is loaded ONE times for a new surfer until he passes again on the .htaccess level and that levle/.htaccess has changed meanwhile. for fastest .htaccess editing I SSH to my site and use "vi" editor to change/edit/add/outcomment a line in my .htaccess then write changes ( :w ) in vi and test - if success then :x, else change back and :x - if wrong I quit vi without saving = :q! study vi to know the simple commands - they all start with colon ( : ) to test instantly your changes best is you are with your browser IN same folder level as your changing .htaccess another story is if you make changes in server configs of your apache years ago I was VPS hosted at 1and1 and they had a full httpd.conf on user level an apache config ONLY gets reactivated next time apache restarts or reloads. server admins never do that for fun - but by default apache makes a graceful restart ( reload ) after next access_log rotate, hence normally once a day according to cron jobs for logrotate. since you are new to such stuff: if you have a Linux box at home, use your localhost to practice. you can have a full copy of your site depending on pages loaded you may either use full functionalities of your site instantly in your http://localhost - if you place all files in the folder your localhost uses and if NO yourdomain.com links are in your site but only relative links. offline practicing is cheaper and faster and if ever you need your host to do some major changes on your website's apache / system config, then you KNOW what changes exactly if you practice all offline AND if you have exact same versions of apache/php/mysql etc offline in your localhost machine. stay as simple as possible with all you do keep as many flatfiles as possible - it saves resources always have a KNOWN and very good reason ( i.e. security or speed ) when making changes learn from scratch as much as possible to be able to do all yourself and thus also to be able to make corrections instantly when things to bad or wrong hence my rule for myself is to always stay within MY OWN limits of skills and knowledge = to never use techniques I have NO idea about. Happy New Year and Merry Christmas all future days all year long !