View Full Version : htaccess file
SuperMan
10-11-2011, 02:33 PM
I have redesigned a site and many of the pages have changed from example.html to example.php - I am assuming it is good practice to 301 redirect all these .html pages to .php ??
Does anyone have the correct code to do this in my htaccess ?? Your thoughts ?
this is what I have been using ...
redirect 301 /index.html http://www.mysite.com/index.php
redirect 301 /about.html http://www.mysite.com/about.php
thanks
weegillis
10-11-2011, 03:50 PM
Another option would be to set your server to parse html as php, then you don't need to change the extensions or apply a redirect.
SuperMan
10-11-2011, 04:15 PM
however all the naming conventions dont correlate to do this... ie some of the file names have changed...
weegillis
10-12-2011, 01:16 AM
Then redirects are your only choice. Sucks that names have changed, it makes cross referencing a nightmare and some files will ultimately get left out on the first and second pass. Your have no choice. Be careful, be thorough, and drink lots of coffee. It's going to be a long night.
NetProwler
10-12-2011, 05:04 AM
The erudite Weegillis has covered the main points. If you have a long list of directives to enforce the redirection, depending upon the number of pages, you may have to resort to a script to trap the 404 pages and then through a look up table, you can do the redirection. It is convoluted, but it may save you the overhead latency.
Your redirection directive is ok.
RedirectPermanent /index.html http://www.mysite.com/index.php will work just as well.
You may also consider for a page that no longer can be correlated to a new page - issue a 'Gone' directive like this:
Redirect 410 /old.html
Kristos
10-12-2011, 06:53 PM
Superman:
the code to add to the .htaccess file in the root to cause all .html & .htm files to be treated as php
for the purpose of using php code in htm/html files is:
<Files *.html>
SetHandler application/x-httpd-php
</Files>
<Files *.htm>
SetHandler application/x-httpd-php
</Files
SuperMan
10-13-2011, 05:33 PM
its kind of fun working with htaccess files - just because I havent done this before and we always need to be learning... I did not know you could actually code PHP in HTML pages - interesting... this will come in handy in some of my other projects... Does anyone know if you can use something similiar to htaccess on a Windows server - I have about 400 .asp pages and many links to them ??
weegillis
10-13-2011, 07:17 PM
There are actually a number of possible directives to configure your server for parsing html as php:
williamc Here are the standard ones that work on most servers (http://www.webproworld.com/webmaster-forum/threads/104994-PHP-or-Xhtml-or-Html5?p=539186&viewfull=1#post539186)
These two I got from 1&1 support:
AddType x-mapp-php4 .html .htm
If you want to use PHP5 instead of PHP4 then use the following line instead:
AddType x-mapp-php5 .html .htm
NetProwler
10-14-2011, 12:20 AM
its kind of fun working with htaccess files - just because I havent done this before and we always need to be learning... I did not know you could actually code PHP in HTML pages - interesting... this will come in handy in some of my other projects... Does anyone know if you can use something similiar to htaccess on a Windows server - I have about 400 .asp pages and many links to them ??
Actually you can assign any file extension to be parsed by the server - not just .html/,htm alone. Windows server doesn't have the exact equivalent of mod_rewrite module which does the job reading the directives you have written in .htaccess. But there are third party extensions to achieve similar effects - ISAPI_rewrite. At least this was the case for IIS 5/6 versions.