I am able to deploy react app on apache server, to login and the home page displays. All links work properly.
The problem occurs when I refresh the page (using F5). It says:
The requested URL /home was not found on this server.
I did almost everything like RewriteEngine set to On in .htaccess file.
RewriteEngine On RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.html [L]
Am I missing something?
You .htaccess seems okay, but it might be ignored by Apache.
You should
Check if AllowOverride is set to All for the Directory you're serving the website from (in your Apache vhost configuration file, under /etc/apache2/sites-enabled)
Check if the rewrite mod is enabled (enable it with sudo a2enmod rewrite, then restart Apache with sudo systemctl restart apache2)
Related
I have been trying to shorten URLs with apache .htaccess file, and currently I have this code:
RewriteEngine On
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^(.*)$ show.php?page=$1 [NC, QSA, L]
AllowOverride All
With this code, for example https://example.com/welcome should be redirected to https://example.com/show.php?page=welcome, but it is not. When I run sudo a2enmod rewrite, I get the following:
Module rewrite already enabled
I also tried to run service apache2 restart. How can I solve it?
I followed the steps outlined here.
I copied and paste the code below in .htaccess file. The .htaccess file is in the same repository that contains my dist folder that I am going to deploy on apache.
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
When I access localhost/dist everything goes fine, since it will use my index.html file and it will automatically redirect to localhost/dist/login. Now if I request directly localhost/dist/login, apache complains and displays The requested URL /dist/login was not found on this server. It seems for me that apache does not picked up my .htaccess settings. Is there something I am doing wrong?
Finally I found a way to solve my problem. Maybe this could help some. I enabled the rewrite mode of Apache and instead of
RewriteRule ^ /index.html,
I wrote
RewriteRule ^ /dist/index.html
and this solved my problem.
I am having the same issue
My .htaccess file in project/ is
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
server : apache
and the command "a2enmod rewrite" shows that "Module rewrite already enabled"
when i point the browser to project folder i can see the folder structure , when i point to project/public then i can see "Hello world." I am using ubuntu elementary os. Am i Following correctly or is there any error in my installation.
when i point the browser to project folder i can see the folder structure , when i point to project/public then i can see "Hello world."
your server should be configured so you can't see the project folder from the browser, the root of your virtualhost should be the public folder
Is IfModule closed?
What you see when you go to another uri? Phalcon's error or Apache 404?
Try to disable mod rewrite, restart apache and then enable it again
a2dismod rewrite
service apache2 restart
a2enmod rewrite
service apache2 restart
I get this error to, but i don't know exactly how i fix it...
I have frusted doing all things given on web for htaccess get working on ubuntu. But I could not do it. Actually I want to run my CodeIgniter app on LAMP, its not production server. so in www directory, there could be multiple folders e.g.
www/punepchub
I access url localhost/punepchub/support/ , it gives 404 error
I want to redirect above link to localhost/punepchub/index.php/support/
using htaccess, following are the contents of htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Where as above mentioned htaccess works perfect on wamp as well as lamp given by godaddy hosting, but it is not working on LAMP server setup on my local ubuntu 12.04 desktop machine
I think apache is not accessing the htaccess file.
I tried following but It didn't worked
I have installed lamp using tasksel
Enabled Rewrite module using command: sudo a2enmod rewrite
It displays the module in the list given by command: sudo apache2ctl -M
Changed etc/apache2/sites-available/default file with AllowOverride All, Also I did same in etc/apache2/sites-enabled/000-default
I have 777 permissions for project folder and files
Also I am confused about Is there any need to create virtual hosts, as this is not production server.
Please help me I really don't know how resolve this issue now.
In advance many thanks
Try this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /punepchub/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /punepchub/index.php [L]
</IfModule>
Actually my website works in localhost, why do I get Internal Server Error in live?
I have attached my .htaccess file here, are there any errors in it?
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# Make backend accessible via url:
RewriteRule ^sysadmin& backend.php
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule ^.*$ /index.php [L]
Just try to add the following rule in your htaccess:
RewriteBase /
You should check your apache log. I had same problem, and I checked error log. There was an error that invalid command "RewriteEngine" It means rewrite module is disabled. You must enable it. For linux:
Under Apache 2+ you can simply do:
sudo a2enmod rewrite && sudo service apache2 restart
or
sudo a2enmod rewrite && sudo /etc/init.d/apache2 restart