'RewriteRule not working with virtual host
I am facing an error when using xampp.
My site is ecom on localhost i.e., http://localhost/ecom. Similarly developing other sites say idiscuss i.e., http://localhost/idiscuss.
In httpd.conf
----------------
DocumentRoot "C:/xampp/htdocs"
RewriteEngine On
RewriteCond C:/xampp/htdocs/%{REQUEST_FILENAME} !-f
RewriteCond C:/xampp/htdocs/%{REQUEST_FILENAME} !-d
RewriteRule ^/ecom/(.*)$ /ecom/index.php?do=$1&%{QUERY_STRING} [L]
This condition removes .php extension as well as, directs every request to index.php, i.e., single entry point.
My file structure is
C:/xampp/htdocs/ecom
, which in turn has index.php
and other php_class
, js
, css
folders.
Every time I have to access:
- localhost/ecom/ - for default home page
- localhost/ecom/contactus
- localhost/ecom/product
Instead, I want to use:
- ecom.com - for default home page
- ecom.com/contactus
- ecom.com/product
To attain this,
a) in httpd-vhosts.conf
--------------------------
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/ecom"
ServerName ecom.com
</VirtualHost>
b) hosts file
-----------------
127.0.0.1 ecom.com
c) httpd.conf
---------------------
RewriteEngine On
RewriteCond C:/xampp/htdocs/%{REQUEST_FILENAME} !-f
RewriteCond C:/xampp/htdocs/%{REQUEST_FILENAME} !-d
RewriteRule ^/ecom.com/(.*)$ /ecom/index.php?do=$1&%{QUERY_STRING} [L]
But it's giving absurd results. I am only able to open the home page, i.e., ecom.com, but when trying to access ecom.com/product, it says "requested url doesn't exist".
Moreover, when trying to access other sites that I am developing, e.g., localhost/idisucss, it throws the same error: "requested url doesn't exist".
I am completely stuck, any help would be appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|