Mod rewrite enabled but not working in Apache - apache

I currently use an iMac running Mavericks for development at work. I use the built in version of Apache and installed MySQL using homebrew when I first got the machine. Recently I had an issue where one of my virtual hosts was not working as expected and I ended up using Virtual Host X's restore command to wipe out my virtual hosts and start again.
I managed to get my vhosts working again but since then have noticed that mod_rewrite, although enabled, is not working. If I go to http://mywebsite.local/events I get an error
"Not Found -The requested URL /events was not found on this server." but if I go to http://mywebsite.local/index.php/events view the page fine.
I think restoring using Virtual Host X may have corrupted something in my Apache set up as the restore command does have this warning:
"Backup files contain all of your VirtualHostX data as well as copies of your web configuration files. Restoring a backup will replace those files and your current data (virtual hosts, domain details, etc) with the previously backed up data."
Here is a copy of my vhost settings for one of the sites I'm having issues with:
Options FollowSymLinks
AllowOverride None
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|gif|jpg|png|css|ttf|woff)$ /index.php
I first experienced this issue on Mountain Lion but have since upgraded to Mavericks hoping it would fix the issue but to no avail.
Any help would be great. If the issue can't easily be solved anyone with any advice about how to completely rid your machine of Apache and start again would also be helpful.

Thanks for your answer but unfortunately it didn't work out. However I am pleased to say the issue is now sorted. I pasted in your code and it stopped my virtual host from running altogether. I needed to paste my original code back in so copied and pasted it back in from this post in Stack Overflow and restarted Apache. I clicked on a few links and the rewrites are now working.
I'm guessing that there were some hidden characters which were causing the issue which were eradicated when I pasted the code back in.
I hope this helps someone as it was very annoying.

This should be used in Debian Apache2:
Options FollowSymLinks
AllowOverride None
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|gif|jpg|png|css|ttf|woff)$ /index.php [L]

Related

Firefox/chrome shows apache request as blocked / stalled

I'm using Apache 2.4.33 running on MacOs 10.13.6 as a local web development server
I ran some updates last week, mainly to update php from 7.1 to 7.2. This included a few tweaks to my httpd.conf namely to load a different php module.
I also recreated the server self-signed certificates as per instructions here: https://gist.github.com/jonathantneal/774e4b0b3d4d739cbc53
I've started getting errors on some web pages where some files included in the page are blank. these are both .js and .css files.
If I refresh the page, it is always the same 2 or 3 files.
As this is a dev environment, the files are sym linked from the web/assets directory through to the source directories.
I can't see any permissions problems. Other files in the same directory, with same ownership and permissions don't have the same error.
Looking at the network panel in FF, it lists the file, no error status, not even 200 - completely blank. I can't see the file in the Apache access_log either. Nothing in the error log.
If I look at the "Timings" sub-tab, it has a status of blocked.
I'm not running the MacOs firewall.
My htaccess is very basic:
Options +FollowSymLinks
IndexIgnore */*
# We need mod_rewrite for enablePrettyUrl
RewriteEngine on
RewriteBase /
# If the directory or file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
It's not CORS/cross domain ...
In FF the console gives a "Loading failed" error
in Chrome it gives "net::ERR_EMPTY_RESPONSE"
So, blocked by what?
it seems as though I had 2 versions of PHP installed. Apache line though I was using a homebrew installed version of 7.0 and the command line thought I was using the native 7.1
I guess somehow these were conflicting.
I ran brew uninstall php#7.0, brew cleanup & brew prune. Rebooted and everything worked OK.

An unprecedented error with placing the Yii2 application vhost

I have encountered so far an unprecedented problem when creating a vhost for the Yii2 application. In principle, I do as usual, but the application does not want to start and shows the error NET :: ERR_CERT_AUTHORITY_INVALID which is not understandable at the moment. I am asking you for help because I have no idea what I can do wrong.
I am using Windows 7, Apache / 2.4.25, PHP 7
Below is the configuration of http-vhost.conf:
<VirtualHost *: 80>
    ServerName aio.localhost
    DocumentRoot "C:/xampp/htdocs/aio/panel/web"
    <Directory "C:/xampp/htdocs/aio/panel/web">
        Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
    </ Directory>
    ErrorLog "C:/xampp/htdocs/aio/panel/runtime/logs/server_error.log"
    CustomLog "C:/xampp/htdocs/aio/panel/runtime/logs/server_access.log" combined
</VirtualHost>
Below are the host definitions:
127.0.0.1 aio.localhost
Here I put a photo with the folder structure:
And here its error from browser:
Have any of you encountered this problem by trying to put the application in Yii2?
And now it work fine. Sorry for the question.
Okey I found a problem in panel/web/.htaccess. I remove lines:
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]

Rewrite Rules for apache (coming from IIS)

I thought I had this worked out... but I guess not. I am currently moving our server from IIS 7 to Apache (2.2.22 Ubuntu), I am able to get all my virtual hosts setup and running perfectly, but one site I am moving needs rewrite rules that I made in IIS, and I am unable to get working on Apache.
My rules are
RewriteEngine on
RewriteRule ^([^/]+)/?$ /index.php?LANG=$1 [L]
Nothing fancy, but I cannot get it to work, I get a service error if these rules are in the vhost conf file.
Anybody care to shed some (most lily obvious) light on an Apache new comer?
Cheers

Apache RewriteCond - Works local, not on Host

I have a .htaccess rewrite condition / rule, which works fine on my local, which is OSX mavericks, running apache Apache/2.2.26, but when I deploy to my production server it no longer works, running Apache/2.2.22 (Debian).
this is the condition:
RewriteCond %{REQUEST_URI} ^([a-z]{2})/sitemap.xml$
RewriteRule ^([a-z]{2})/sitemap.xml /sitemaps/$1_sitemap.xml [NC,L]
As you can see, I have a directory for sitemaps in the base directory, and this being a multi-lingual site, I have a sitemap for each language. However I cannot simply create a directory like /en/sitemap.xml for each one, as this effects how the framework deals with the request, as apache trys to serve the directory, rather than passing it to the index file to be handled.
So i create this rewrite condition, which should rewrite the request /en/sitemap.xml to /sitemaps/en_sitemap.xml and as stated, this works great locally, but not on my Debian server, it never matches that regex from the request, it just moves onto the next one and passes the request to the index.php file.. which is wrong!
Any advice / help would be great, I cannot find anything in apache docs referring to mod_rewrite under these 2 versions that may be different.
Thanks
That's because %{REQUEST_URI} value always begins with a leading slash.
Also, your condition is useless since your RewriteRule does the same.
This code should work as expected on both sides
RewriteRule ^([a-z]{2})/sitemap\.xml$ /sitemaps/$1_sitemap.xml [L]

apache resolving urls before looking in .htaccess

I have a rewrite rule of the following form:
RewriteRule ^foo/([a-zA-Z0-9]+)$ foo.php?arg=$1 [qsa,nc]
It takes urls of the form /foo/bar and changes them to /foo.php?arg=bar
It works properly locally, and it works on my old host but I moved to a new host (running ubuntu) and it behaves differently.
On the new host apache notices that there is a foo.php and calls it directly. In other words, urls of the form /foo/bar are seen as /foo.php. If I rename foo.php to foo_junk.php and change the rewrite rule to be
RewriteRule ^foo/([a-zA-Z0-9]+)$ foo_junk.php?arg=$1 [qsa,nc]
Then it all works. So it's not that I didn't enable overrides or that I failed to install mod_rewrite or anything. Rewrites work, they're just being done at a different point in the process of resolving a url than they are locally.
Is there a configuration option for this?
Try disabling MultiViews:
Options -MultiViews