.htaccess is ignored on Apache - apache

I've made a website in PHP, tested it locally and it works fine. Now I pushed it to my actual webserver and now I'm having trouble, because my .htaccess - file should redirect all calls, but it's getting ignored.
This is my .htaccess - file
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
RewriteRule ^(controllers/|core/|models/|views/) - [F,L,NC]
</IfModule>
I've already searched for a solution and came up with running these commands:
a2enmod rewrite
a2enmod expires
a2ensite default-ssl
After each command i restarted the server.
The last command in the list above gives me an error:
apache2: Syntax error on line 224 of /etc/apache2/apache2.conf: Syntax error on line 166 of /etc/apache2/sites-enabled/default-ssl.conf: Expected </VirtualHost> but saw </IfModule>
Action 'configtest' failed.
Does someone have a solution for this?

Look in your /etc/apache2/sites-enabled/default-ssl.conf file. Does it have one <VirtualHost> opening entry without the corresponding </VirtualHost> closing entry?

Related

MAMP Apache Server - One Subdirectory Works, Another Doesn't

I am running an Apache server through MAMP.
I have two directories inside htdocs: TWS and SHR
SHR and TWS are two totally separate wordpress installations each with their own .htaccess files (which were previously working).
The .htaccess files are identical except TWS is replaced by SHR
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /TWS/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /TWS/index.php [L]
</IfModule>
My problem is that localhost:81/TWS is accessible while localhost:81/SHR returns a 500 error.
apache/httpd.conf contains a directory for htdocs
<Directory "F:\MAMP\htdocs">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
and the DirectoryIndex is set to use index.html or index.php.
Both TWS and SHR have an index.php file at their root level.
I have checked all of the logs that I can find related to apache, php, mamp, and even mysql. None of the logs indicate an error.
What else can I try?
It turns out there was just a simple syntax error in one of the PHP files that I was editing.
The error got logged inside the wordpress log itself rather than the MAMP php logs.
That is, MAMP/htdocs/SHR/wp-content/debug.log
Once I resolved the php syntax error, everything worked fine again.

Url Not found on reload + Angular5

I am facing one issue related to the angular app, using components in my app then when I go with the single page the page loaded successfully but when I open that URL in a new tab or reload it, give error Not found.
I am using AWS apache server for this and only facing this issue on it, in my Godaddy server page reloading working properly.
Here I am attaching my screenshot of the error.[
Thankx in advance
I think your .htaccess file is not reachable,
Create .htaccess file inside /var/www/html i.e. in the folder where your index.html is.
Put following code in it:-
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
Than goto /etc/apache2 folder and open apache2.conf file with sudo.
cd /etc/apache2
sudo vim apache2.conf
Remove comment(#) of AccessFileName it will look like
AccessFileName .htaccess
Then find the line where there is
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
replace "None" with "All"
AllowOverride All
Done!
Now run command
sudo service apache2 restart
And check now!
Add .htaccess file in your project root folder.
bellow code add in your Appache .htaccess file:
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
Nginx .conf file :
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.html break;
}
}
execute command :
sudo a2enmod rewrite
sudo service apache2 restart

mod-rewrite RewriteRule ignored in document root .htaccess file

I have the following at the top of the .htaccess file in the root of my virtual host:
RewriteOptions inherit
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/blog(/.*)?$ [NC,OR]
RewriteCond %{REQUEST_URI} ^/mobile(/.*)?$ [NC]
RewriteRule (.*) /? [R=301,L]
</IfModule>
This block validates out using the htaccess tester and returns the desired results. However, when I hit the webserver -- Apache 2.4.6 -- I only receive 404 errors when requesting http://www.domain.com/blog; with or without the trailing slash. The conf file for the vhost allows overrides and is configured to allow the following of symlinks. I also verified that httpd is seeing the .htaccess file by adding some junk in the file which resulted in a http status of 500; the desired results.
The reason that I am not using Redirect or RedirectMatch is that I need to quell the querystring from the initial request. Otherwise, either of those directives works fine. Any ideas as to why this is failing on the server and not the tester is greatly appreciated. Thanks.

Internal Server Error in yii

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

why apache server redicect /doc to usr/share/doc

I have the rewrite ruls in .htaccess file under /var/www in my ubuntu10.4 server like below, When the url appears to be http://127.0.0.1/doc/view, the webpage shows "The requested URL /doc/view was not found on this server", and then I check the apach log, it logs "File does not exist: /usr/share/doc/view", so apprently apache redirect the /doc/view to /usr/share/doc/view. I don't know what it is going on here, can anybody help? thanks for help.
Options +FollowSymLinks
IndexIgnore */*
<IfModule mod_rewrite.c>
RewriteEngine on
# 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
</IfModule>
Apache's default config on many distributions makes it so you can go to http://localhost/doc/to read the Apache documentation. You can edit this out in your httpd.conf or apache2.conf file if you need to use /doc for your own URLs.