0

I've tried to add the item below in .htaccess(wamp64\bin\apache\apache2.4.37\conf) and enabled Use URL Rewriting in Joomla however when I try to type abc.com in search engine address bar it will still redirect me to search page instead of redirecting me to the website. I've also performed checking and confirmed that .htaccess file is readable, the webpage is work when go to https://www.abc.co m however redirection still not work. I just need the page to redirect from http://abc.co m to https://www.abc.co m Is there any other way to do it? Or I'm doing it wrongly?? Please help.

RewriteCond %{HTTP_HOST} ^abc.com [NC] 
RewriteRule ^(.*)$ https://www.abc.co m/$1 [L,R=301]
Petri
  • 5
  • 7
  • Tested the redirect locally, and it seems to work fine. Normally, an .htaccess file is in the public_html folder of the website (not in the apache conf folder). Have you tried putting the file in the root of the website? (And other applicable folders.) Or is there another rule interfering? – Jason Dec 20 '19 at 07:30
  • Hi Jason, I've been go through folder but can't find any public_html folder inside :( It should be a simple work that switch from non www to www but it seems to become tough now :((( – Petri Dec 20 '19 at 07:56
  • I hear you. Apache configs are not the most user-friendly. :) The root folder would be where you keep your HTML/PHP/JavaScript/etc. and would not normally be in your wamp64\bin\apache\apache2.4.37\conf. It looks like for WAMP it's a folder called "www" instead of "public_html". Should be somewhere like "c:/wamp/www" if you're on windows. https://stackoverflow.com/questions/6233572/where-is-the-web-server-root-directory-in-wamp/6286385 – Jason Dec 20 '19 at 08:03
  • Thanks for help Jason! While looking for the correct path, do I need to restart the Wamp services after the changes done? Or it will immediately change? – Petri Dec 20 '19 at 08:15
  • It should change without needing to restart. – Jason Dec 20 '19 at 08:16
  • No problem. I'll write up an answer to document the solution. – Jason Dec 20 '19 at 08:36

1 Answers1

0

The redirect itself works great. The issue is where you've put the file.

.htaccess files are meant to be in the root folder and sub-directories of your website, not in the config files for Apache. Think of them as configuration files the server will find on-the-fly as it serves up documents, not static configurations loaded when the server starts (which are found in the "conf" folder you referred to). (See https://httpd.apache.org/docs/current/howto/htaccess.html)

For WAMP, the root folder is typically a folder called "www" and is normally located at c:/wamp/www. See Where is the web server root directory in WAMP? More commonly, though, this folder is called "public_html" (such as with LAMP, XAMP, MAMP, or default Apache installs).

Jason
  • 556
  • 1
  • 5
  • 21
  • Hi Jason, is there any way I can do the testing locally as I don't want to mess up our live server. – Petri Feb 05 '20 at 06:24
  • Sure, you can always run Apache on your computer and follow the same steps. (e.g. you can install WAMP/MAMP/XAMP on you machine and follow the steps described.) – Jason Feb 05 '20 at 21:16
  • Hi Jason, I've tried adding the above line to .htaccess file, AllowOverride all in httpd.conf file, enabled Use URL Rewriting from Joomla, but none of those work. I've test mod_rewrite is working but still, redirection still did not work. I've run out of idea now :((( – Petri Feb 14 '20 at 01:46