JING Posted May 29, 2014 Share Posted May 29, 2014 When I type my web address with www, everything will be fine. But when I type my address without www, it will show 404 page. I think my website needs to be redirected. I could not find htaccess file from the file folder of the C-panel. Can someone please let me know how to find the htaccess file or create a htaccess file. If it possible, please write down the code here as well. Thanks. Link to comment Share on other sites More sharing options...
starsg38 Posted May 29, 2014 Share Posted May 29, 2014 You can open up notepad or text editor and type in the following code: RewriteEngine on rewritecond %{http_host} ^yourwebsite.com [nc] rewriterule ^(.*)$ http://www.yourwebsite.com/$1 [r=301,nc] and save the file as .htaccess with the Save as type set to "All Files" Put it in your root directory. If this doesn't work the Rewrite Engine might be turned off on your server. 1 Link to comment Share on other sites More sharing options...
El Patron Posted May 29, 2014 Share Posted May 29, 2014 to add something similar but without any hardcoding of url and checking for rewrite module exists. <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] </IfModule> this would go in the top of your .htaccess Link to comment Share on other sites More sharing options...
JING Posted May 30, 2014 Author Share Posted May 30, 2014 Thank you guys! It works well! Link to comment Share on other sites More sharing options...
JING Posted May 30, 2014 Author Share Posted May 30, 2014 One more question. Why my website is soooo slow after uploading the .htaccess file? I copied the code"<IfModule mod_rewrite.c> RewriteEngine OnRewriteCond %{HTTP_HOST} !^www\.RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] </IfModule>" and saved it into text editor, named it as1.htaccess, then, uploaded into my root directory. Is there anything wrong? Link to comment Share on other sites More sharing options...
stephenward Posted May 30, 2014 Share Posted May 30, 2014 When I type my web address with www, everything will be fine. But when I type my address without www, it will show 404 page. I think my website needs to be redirected. I could not find htaccess file from the file folder of the C-panel. Can someone please let me know how to find the htaccess file or create a htaccess file. If it possible, please write down the code here as well. Thanks. you can do it easily on your cpanel of the website Link to comment Share on other sites More sharing options...
El Patron Posted May 30, 2014 Share Posted May 30, 2014 One more question. Why my website is soooo slow after uploading the .htaccess file? I copied the code"<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] </IfModule>" and saved it into text editor, named it as1.htaccess, then, uploaded into my root directory. Is there anything wrong? Here they tell us using .htaccess is bad for httpd (apache) peformance. http://httpd.apache.org/docs/2.2/howto/htaccess.html#page-header we get lazy using .htaccess, and as they say the 'the lazy work twice' Link to comment Share on other sites More sharing options...
starsg38 Posted May 30, 2014 Share Posted May 30, 2014 I usually name it just .htaccess without any file name in front of it. I don't know if that could have anything to do with it. Link to comment Share on other sites More sharing options...
El Patron Posted May 30, 2014 Share Posted May 30, 2014 I usually name it just .htaccess without any file name in front of it. I don't know if that could have anything to do with it. httpd configuration file is not accessible via FTP. what they suggest is rather than using the .htaccess file, that it be done at apache configuration level. contact your hosting company on how/if you can manage apache configuration. Honestly we tell people put this in .htaccess as a general rule because they know what that is and they can access it using FTP. Link to comment Share on other sites More sharing options...
JING Posted May 30, 2014 Author Share Posted May 30, 2014 you can do it easily on your cpanel of the website Can you share how? Link to comment Share on other sites More sharing options...
Recommended Posts