Apache virtual host .htaccess and react router - windows

I am running a windows 10 machine with apache 2.4. I am trying to deploy my website to my apache webserver but the routes are not working.
For example, when I go to http://my.domain.com/ I see the website root. But when I try to go to http://my.domain.com/users I get a 404 error.
I am using a virtual host to run my website so it doesn't interfer with mine main domain.
Here are my settings:
React redux routing:
ReactDOM.render(
<Provider store={store}>
<Router history={browserHistory}>
<Route component={App}>
<Route path="/" component={HomePage} />
<Route path="/users" component={UsersPage}/>
<Route path="/user" component={UserPage}>
<Route path="/user/:id" component={UserPage}/>
</Route>
<Route path="*" component={NotFoundPage}/>
</Route>
</Router>
</Provider>,
document.getElementById('app')
);
.htaccess:
RedirectMatch ^/oauth2/redirect/(.*)$ $1
<ifModule mod_rewrite.c>
#######################################################################
# GENERAL #
#######################################################################
# Make apache follow sym links to files
Options +FollowSymLinks
# If somebody opens a folder, hide all files from the resulting folder list
IndexIgnore */*
#######################################################################
# REWRITING #
#######################################################################
# Enable rewriting
RewriteEngine On
RewriteBase /
# If its not HTTPS
# RewriteCond %{HTTPS} off
# Comment out the RewriteCond above, and uncomment the RewriteCond below if you're using a load balancer (e.g. CloudFlare) for SSL
# RewriteCond %{HTTP:X-Forwarded-Proto} !https
# Redirect to the same URL with https://, ignoring all further rules if this one is in effect
# RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [R,L]
# If we get to here, it means we are on https://
# If the file with the specified name in the browser doesn't exist
RewriteCond %{REQUEST_FILENAME} !-f
# and the directory with the specified name in the browser doesn't exist
RewriteCond %{REQUEST_FILENAME} !-d
# and we are not opening the root already (otherwise we get a redirect loop)
RewriteCond %{REQUEST_FILENAME} !\/$
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# Rewrite all requests to the root
RewriteRule ^(.*) /
</ifModule>
httpd-vhosts.conf
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin myemail#nbnet.nb.ca
DocumentRoot "D:/my.domain.com"
ServerName my.domain.com
ServerAlias mystify.homenet.org
ErrorLog "logs/my.domain.com-error.log"
CustomLog "logs/my.domain.com--access.log" common
<Directory "D:/my.domain.com">
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin myemail#nbnet.nb.ca
DocumentRoot "D:/my.domain.com/lln4"
ServerName lln.domain.com
ErrorLog "logs/lln.domain.com-error.log"
CustomLog "logs/lln.domain.com-access.log" common
<Directory "D:/my.domain.com/lln4">
Options FollowSymLinks
Options All
Include D:/my.domain.com/lln4/.htaccess
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
anyone have any idea why the sub pages of my website arn't working?

Related

How to redirect calls from my-domain/api/specific-route to my-domain/api/api/specific-route?

I have a site being served by an Apache server, with the following structure:
On the main directory, I have a front-end app.
On a subdirectory named API, I have an API running on Laravel.
When I make calls to the API the URL look like this: domain/api/api/specific-route
I would like it to look like this: domain/api/specific-route
This is the relevant part of the virtual host config file:
ServerName my-domain.com
ServerAlias www.my-domain.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/my-domain
<Directory /var/www/my-domain>
RewriteEngine On
RewriteBase /
# Serve files when they are found
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# When file is not found, serve index.html instead
RewriteRule ^ /index.html
</Directory>
<Directory /var/www/my-domain/api>
RewriteEngine on
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
ErrorLog /var/www/my-domain/error.log
CustomLog /var/www/my-domain/access.log combined
# Aliases
Alias /api /var/www/my-domain/api/public

i get access forbidden from Apache (httpd) in fedora 34, Laravel, SELinux

I have configured httpd in my fedora and I checked everything is true but i get
access forbidden
I have tested everything about .htaccess but still getting access forbidden. also, my laravel folder permissions are correct.
I tested a sample project while installing httpd it worked perfectly with no 'access forbidden' message.
this is my httpd config
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot /home/myuser/gitlab/register/public
<Directory /home/myuser/gitlab/register/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
this is my htaccess in laravel public folder
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
your probably creating the issue by mixing old Apache syntax with new Apache syntax, modern versions of Apache should be something like this...
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot /home/myuser/gitlab/register/public
<Directory /home/myuser/gitlab/register/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
# Order allow,deny
# Allow from all
</Directory>
</VirtualHost>
I found the problem.
it is because of the
SELinux
ubuntu does not uses SELinux by default but RedHat distributions use it by default. SELinux prevents apache to access the home directory for the sake of security so if you disable or put it to Permissive mode, apache can access your home directory to load the web project. if you do not want to disable SELinux so the correct location for web applications is in /var/www/ folder
so if we change httpd config to
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot /var/www/gitlab/register/public
<Directory /var/www/gitlab/register/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
it works fine

Laravel project routes not working when app is accessed over the network

when I access the application from same computer where wampServer is installed every thing works fine whether I access it using localhost or Ip of the computer but when I put wamp server online and access the same app from another computer using the Ip of the computer where wamp is installed routes doesn't work for me only root page is being accessed and if I click on any other link I get 404 error
Here is .htaccess file in public folder
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteBase /laravel/itman/public/
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
httpd-vhosts.conf file in wamp\bin\apache\apache2.4.41\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
The apache virtual host should point to the public directory for your laravel project.
e.g.
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www/public"
<Directory "${INSTALL_DIR}/www/public">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

laravel 5.6 and apache gives 404 for urls

I have apache2 server on Ubuntu 16.04LTS and I have Laravel 5.6 project called book_donation in /var/www/html now when I visit localhost the Laravel welcome screens appear no problem but whenever I click on any url it gives:
Not Found
The requested URL /book_donation/public/login was not found on this
server. Apache/2.4.18 (Ubuntu) Server at 127.0.0.1 Port 80
and here is .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and here is my /etc/apache2/site-available/000-default.conf:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory "/var/www/html">
AllowOverride all
Require all granted
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
My php version is 7.1 and apache version is 2.4.18, how to solve this?
As stated in the docs, you should configure your web server's document / web root to be the public directory.
Create a new file /etc/apache2/site-available/book_donation.test.conf:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName book_donation.test
ServerAlias www.book_donation.test
DocumentRoot /var/www/html/book_donation/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Edit your /etc/hosts file and add the following:
127.0.1.1 book_donation.test
Then run:
sudo a2ensite book_donation.test.conf
sudo service apache2 restart
Then you should be able to visit book_donation.test and see your site.
I was facing same problem any new route was not working and gave 404 error. Also check php artisan route:list where new route details showing properly but still it was not working. I also tried following command to make it work
php artisan view:clear
php artisan config:clear
php artisan cache:clear
Here are my project details
My DocumentRoot is /var/www/html/project/public. when add new route in web.php, it was nor working and gave 404 error but root route was working fine. Means any new route was working. so I did following changes and it start working.
changed in /etc/apache2/sites-available/project.conf
<Directory /var/www/html/project/public>
**Allowoverride All**
and enable url rewrite by running sudo a2enmod rewrite
restart apache server by running sudo systemctl restart apache2

Redirect home URL to Magento folder

I have Magento installed on my site at mydomain.com/magento. I'm happy with it to stay in this directory, however when people visit the site directly (i.e. mydomain.com) I would like this to open the Magento folder. How can I do this?
Thank you very much.
You have to make your server redirect "mydomain.com" to the directory you have installed Magento at. If you are using apache you could add a virtualhost like the one below to your httpd.conf:
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot "/yourpath/magento"
CustomLog "/tmp/access_log" common
LogLevel debug
ErrorLog "/tmp/error.log"
<Directory "/yourpath/magento">
Options FollowSymLinks Multiviews Indexes
MultiviewsMatch Any
# Rewrites to allow links
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# We are not allowing any directive contained in a .htaccess file
AllowOverride None
# We grant all permissions
Require all granted
</Directory>

Resources