configure mod_rewrite on localhost windows xampp - apache

I am trying to get mod_rewrite to work on localhost. If I go to localhost/website it loads the
DirectoryIndex home.php
and
localhost/website/home
also works
but for every other page it only shows the home page.
RewriteEngine On
RewriteBase /
RewriteRule ^home/?$ home.php [NC,L]
RewriteRule ^about/?$ about.php [NC,L] <--- this goes to home
http.cfg:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs/website"
<Directory "C:/xampp/htdocs/website">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

Related

Vuejs App still get 404 page after edit .htaccess

I have a Vuejs App deployed at apache2 server in digitalocean , when you hit the url it forwards you to login page which is working fine and then automatic navigate me to dashboard page that have cards when I click on one of cards I get 404 page even after I edit my .htaccess file in dist
NOTE the card route is domain.com/build
I tried .htaccess configuration from docs
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
and here is my virtual host configuration
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin email
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/domain.com/public_html/app/dist
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass /api/ http://localhost:8000/
ProxyPassReverse /api/ http://localhost:8000/
RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.
#RewriteCond %{SERVER_NAME} =domain.com
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
SSLCertificateFile /etc/letsencrypt/live/domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
Nothing wrong with virtual host file, the problem was in apache2.conf file in /etc/apache2. what I need is to change this part from
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
to :
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
you need to change the AllowOverride attribute.

Apache2 mod_rewrite rules

How do i rewrite static files request like
http://example.com/assets/img/logo.png
to
http://assets.example.com/img/logo.png
main site rewrite rules
ServerName example.com
ServerAlias example.com
DocumentRoot /var/www/html/example.com/public/
<Directory /var/www/html/example.com/public/ >
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} !assets\.site\.com
RewriteCond %{REQUEST_URI} \.(png|gif|ico|css|js|tiff|woff|woff2|ogg|mp3)$ [NC]
RewriteRule ^(.*) http://assets.example.com$1 [NC,L]
sub-domain for assets is working properly
virtual host config for assets.example.com
ServerName assets.example.com
ServerAlias assets.example.com
DocumentRoot /var/www/html/example.com/public/assets/
<Directory /var/www/html/example.com/public/assets/ >
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
http://assets.example.com/img/logo.png gives a 404
but if i create a /var/www/html/example.com/public/assets/assets/ then http://assets.example.com/img/logo.png reutns 200
Per your comment, you just need to change the what you're capturing in the regex used by the RewriteRule. Right now $1 is the value of what's in (.*). You can remove "assets" from that by adding it to the path prior to your capture group.
Change:
RewriteRule ^(.*) http://assets.example.com$1 [NC,L]
To:
RewriteRule ^assets/(.*) http://assets.example.com/$1 [NC,L]

Apache http-vhosts not the same as httacces?

I have a new project created in symfony and I configured httpd-vhosts to bypass all htaccess files that exist in the project's path.
<VirtualHost *:80>
ServerAdmin admin#lab.localhost
DocumentRoot "C:\wamp64\www\lab.localhost"
<Directory "C:\wamp64\www\lab.localhost">
AllowOverride None
AllowOverrideList None
Order Allow,Deny
Allow From All
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ /web [L]
</IfModule>
</Directory>
<Directory "C:\wamp64\www\lab.localhost\web">
AllowOverride None
AllowOverrideList None
Order Allow,Deny
Allow From All
DirectoryIndex app.php
Options FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app_dev.php [QSA,L]
</IfModule>
</Directory>
ServerName lab.localhost
ServerAlias www.lab.localhost.com
ErrorLog "logs/lab.localhost-error.log"
CustomLog "logs/lab.localhost-access.log" common
</VirtualHost>
With this config it gives me Internal Server Error. If I set the AllowOverride and AllowOverrideList to All, it works as expected. The rewrite directves listed here are the same in my htaccess file.
Is there any difference between htaccess and httpd-vhosts?
And if not, why doesn't my config work?
Thank you

Apache VirtualHost issue not able to run site with htaccess configuration

I am having two domains example xyz.xx and pqrs.net and pointing to same IP.
xyz.xx apache htaccess configuration was done long back and running perfectly fine with this config
Listen : 80
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin testacc#gmail.com
DocumentRoot /www/docs/xyz.xx
ServerName xyz.xx
ServerAlias www.jxyz.xx
<Directory "/www/docs/xyz.xx">
AllowOverride None
Options All
Order allow,deny
Allow from all
DirectoryIndex index.php index.html index.htm
</Directory>
JkMount /test/*.jsp router
JkMount /test/*.html router
</VirtualHost>
Now I am trying to configure htaccess for pqrs.net but facing difficulties , Not sure why it is happening.Need Help.
Here is my other part of htaccess configuration added for pqrs.net:
Listen : 8081
NameVirtualHost XXX.XX.XX.XX:8081
<VirtualHost XXX.XX.XX.XX:8081>
ServerAdmin hello#gmail.com
DocumentRoot /www/docs/pqrs.net
ServerName pqrs.net
ServerAlias www.pqrs.net
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_REFERER} !^$
RewriteRule ^/$ /xxx/usa/index.html [L,PT]
RewriteCond %{REQUEST_URI} !^/xxx/.*
RewriteCond %{REQUEST_URI} !^.*\.do.*
RewriteRule ^/(.*) /xxx/$1 [L,PT]
JkMount /property/*.jsp xxxrouter
JkMount /property/*.html xxxrouter
<Directory "/www/docs/">
AllowOverride None
Options All
Order allow,deny
Allow from all
DirectoryIndex index.html
</Directory>
</VirtualHost>
and here is my workers.properties
worker.list=router
worker.list=xxxrouter
worker.xxxrouter.port=8011
worker.xxxrouter.host=localhost
worker.xxxrouter.type=ajp13
worker.xxxrouter.reply_timeout=100000
worker.router.port=8009
worker.router.host=localhost
worker.router.type=ajp13
worker.router.reply_timeout=100000
Please help me on this , when i am trying to access pqrs.net , it shows me this error message on browser.
The requested URL /xxx/usa/index.html was not found on this server.

VirtualHost problem

Can someone tell me why I can't view my index.php from the subdir /oorbellenboutique/?
It shows http:// www.oorbellenboutique.nl/startpagina/index.php, but it must be the index.php from f:/inetpub/wwwroot/oorbellenboutique
The correct URL is: http:// www.oorbellenboutique.nl/index.php
My DNS is:
A *.oorbellenboutique.nl → 83.87.163.224
A oorbellenboutique.nl → 83.87.163.224
CNAME www.oorbellenboutique.nl → oorbellenboutique.nl
My URL is: http://www.oorbellenboutique.nl
I'm running Apache 2.x
NameVirtualHost 192.168.0.199:80
NameVirtualHost 192.168.0.199:443
<VirtualHost 192.168.0.199:80 192.168.0.199:443>
ServerName oorbellenboutique.nl
ServerAlias www.oorbellenboutique.nl
DocumentRoot f:/inetpub/wwwroot/oorbellenboutique
RewriteEngine On
KeepAlive Off
DocumentRoot "f:/inetpub/wwwroot"
<Directory f:/inetpub/wwwroot/oorbellenboutique>
DirectoryIndex index.php
Order deny,allow
Allow from all
</Directory>
RewriteCond %{HTTP_HOST} ^(?:www\.)?oorbellenboutique\.nl$
ReWriteRule ^(.*) /oorbellenboutique/$1
</virtualhost>
This works but the URL is now:
http:// www.oorbellenboutique.nl/oorbellenboutique/index.php
How can I make the URL shorter like:
http:// www.oorbellenboutique.nl/index.php
NameVirtualHost 192.168.0.199:80
NameVirtualHost 192.168.0.199:443
< VirtualHost 192.168.0.199:80 192.168.0.199:443>
ServerName www.oorbellenboutique.nl
ServerAlias *.oorbellenboutique.nl oorbellenboutique.nl
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www.)?oorbellenboutique.nl$
<Directory f:/inetpub/wwwroot/oorbellenboutique>
DirectoryIndex index.html index.php
Order deny,allow
Allow from all
</Directory>
RewriteRule ^/$ /oorbellenboutique/ [R]
< /virtualhost>
Try adding a RewriteBase directive immediately following the RewriteEngine directive:
RewriteBase f:/inetpub/wwwroot
That is not the same as DocumentRoot for functionality -- it is needed for mod_rewrite.