Httpd/Apache. PHP. mod_rewrite. Fedora 17 - mod-rewrite

I' trying to install sweetcron and it needs mod_rewrite enabled.
So, what's the easiest way to do this on Fedora 17?

Edit your httpd.conf (by default it lies in /etc/httpd/conf/)
Change option AllowOverride None to AllowOverride All
After that restart your Apache server.
You can test your rewrite engine by some simple redirect:
Options +FollowSymLinks
RewriteEngine On
RewriteRule (.*) http://stackoverflow.com

Related

working .htaccess configs don't work on httpd.conf

An early heads up - I'm a beginner student with Back-end programming and for now, even .htaccess URL rewrites was a huge pain to implement.
I have XAMPP Apache installed on my Mac (not XAMPP-VM) with a website folder called "Project" inside "/htdocs". So basically a website that I'm practicing with URL looks like this - "localhost/Project"
There was one .htaccess file in my "root" ("root" is the "/Project" folder) folder and another one inside a "PHP" folder (i.e. root/PHP/.htaccess).
Root's .htaccess had the following configs:
Options -Indexes
ErrorDocument 403 /Project/index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !(.*)Pages
RewriteRule ^(.*)$ Pages/$1.php [L,NC]
</IfModule>
Whilst root/PHP's .htaccess had this:
Deny from all
Everything worked and after reading a bit more about .htaccess best practices I wanted to move all of the above configs to httpd.conf, specifically the one located inside "/Applications/XAMPP/xamppfiles/apache2/conf". I moved the code to that httpd (properly?), commented out everything inside the previously mentioned .htaccess files, and here's how the httpd now looks like inside:
Alias /bitnami/ "/Applications/XAMPP/xamppfiles/apache2/htdocs/"
Alias /bitnami "/Applications/XAMPP/xamppfiles/apache2/htdocs"
<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs/Project">
Options -Indexes
ErrorDocument 403 /Project/index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !(.*)Pages
RewriteRule ^/(.*)$ /Pages/$1.php [L,NC]
</IfModule>
</Directory>
<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs/Project/PHP">
Deny from all
</Directory>
And it doesn't work. I've tried to google a solution for a while and so far completely nothing. Just in case, I'll also mention that the goal for this "CMS" project is to "write once, install anywhere".
[EDIT]
With some clarifications from #MrWhite, this is what the configs look like in xamppfiles. Also, also, Options -Indexes and /Project/PHP > Require all denied don't work as I can browse folders and access "PHP" folder from Browser. And it did not work prior to this EDIT as well.
-xamppfiles/apache2/conf/httpd.conf
Alias /bitnami/ "/Applications/XAMPP/xamppfiles/apache2/htdocs/"
Alias /bitnami "/Applications/XAMPP/xamppfiles/apache2/htdocs"
<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Include "/Applications/XAMPP/xamppfiles/apache2/conf/httpd.conf"
-xamppfiles/apache2/conf/project.conf
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/xamppfiles/apache2/htdocs/Project">
Options -Indexes
ErrorDocument 403 /Project/index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !(.*)Pages
RewriteRule ^(.*)$ Pages/$1.php [L,NC]
</IfModule>
<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs/Project/PHP">
Require all denied
</Directory>
</VirtualHost>
I'd greatly appreciate any help.
Original:
RewriteRule ^(.*)$ Pages/$1.php [L,NC]
New:
RewriteRule ^/(.*)$ /Pages/$1.php [L,NC]
You shouldn't have changed anything here. You are moving the directives from .htaccess to a <Directory> section (in the server config). These are both directory contexts and work the same way. (You are incorrectly thinking this is a server or virtualhost context, although the target URL-path would still be wrong.)
By introducing a slash at the start of the URL-path in the RewriteRule pattern (first argument) the rule will never match. If it did... the additional slash you've introduced at the start of the substitution string (second argument) would incorrectly rewrite the request to /Pages in the document root, not /Project/Pages as would seem to be the intention.
Note that if you are moving the .htaccess config to <Directory> containers in the server config then you should probably disable .htaccess overrides altogether, since a .htaccess file that contains mod_rewrite directives will completely override the <Directory> container in the server config. For example:
AllowOverride None
Note also that Order, Allow and Deny are Apache 2.2 directives and formerly deprecated on Apache 2.4. On 2.4 you should be using the equivalent Require directive instead. For example:
Require all granted
Require all denied
Extra:
Look into creating additional <VirtualHost> containers for each project, store these in separate files and include them in the main server config, rather than modifying the main server config directly. This will allow you to host multiple (separate) websites on the same webserver.
I have found the issue, which was my blind mistake.
<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs/Project">
Options -Indexes
//...
I was pointing to the wrong htdocs folder that contains my Project and the correct way was:
<Directory "/Applications/XAMPP/xamppfiles/htdocs/Project">
Hope this saves some time for anyone else that would come across this.

CakePHP on a Mac - Homebrew HTTPD

I'm trying to run CakePHP 4 or 3.8 on macOS Catalina with Homebrew httpd and PHP 7.3.13
I run composer as mentioned on cookbook and installation goes well but, when try to run te app via browser I get this error:
safari screen
chrome screen
on error log message get "AH00052: child pid 10126 exit signal Illegal instruction (4)".
I have also the extensions intl, mbscript, pear, rewrite, etc enabled.
My virtual host is like this:
DocumentRoot "/Users/webdev/Sites/cakephp/webroot"
ServerName cakephp.localhost
<Directory "/Users/webdev/Sites/cakephp/webroot">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog "/Users/webdev/Sites/Error_Logs/error.log
the .htaccess file on root of app is:
RewriteEngine on
RewriteRule ^(\.well-known/.*)$ $1 [L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
And in webroot folder is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I've already tried many suggestions but nothing solve the problem.
I don't know what to do more because, just CakePHP don't work and i've other apps like Laravel and work like a charm on this machine.
If anyone can help with solution, thanks in advance.
I figured out what being wrong in my case.
When I configured virtual host and hosts file to "something.localhost" server dropped connection.
Changed configuration to "something.something_else" in httpd-username.conf and /etc/hosts, all cake instances start working.
This works for me.

Apache2 log not displayed for rewrite module and no rewrite

I've VPS in OVH and i developped website with j2ee and i associate apache with tomcat using mod_jk.
when i enter url http://ip_of_vps/myapp, i enter to website.
until now it's ok
now i add rewrite for access to website using only ip_of_vps without context (myapp), for this i'm using Rewrite in apache2.config like this :
<virtualhost *:80>
RewriteEngine On
LogLevel alert rewrite:trace6
RewriteRule ^/$ http://ip_of_vps/myapp/ [P,L]
</virtualhost>
And i change All AllowOverride in directory from none to All
when i try to access to http://ip_of_vps, i've apache2 home page.
what i've forgot ?
I'm using ubuntu 14.04 server, apache2, tomcat7.
Off the top of my head, typically you would write
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
ReWriteRule your rule
</IfModule>
so, is mod_rewrite actually loaded?
do you need your RewriteBase to be /myapp/ ?
my suggestion would be to put a .htaccess in your html root directory
with a rule like
RewriteRule ^myapp/(.*)$ $1 [L]
this way you wont need mod_proxy at all
hope this helps

cakephp url rewriting not properly configured

I'm encountering a problem with my cakephp app...
I'm using Cakephp 2.4.3 with XAMPP on MacOSX Mavericks and I'm getting the message : URL rewriting is not properly configured on your server. 1) Help me configure it 2) I don't / can't use URL rewriting
But I configured the sites according to the url rewriting tutorial...
I have a Virtualhost :
<VirtualHost 127.0.0.1>
ServerName cake84.loc
DocumentRoot "/Users/me/Sites/c84/cakephp"
DirectoryIndex index.php
<Directory "/Users/me/Sites/c84/cakephp">
AllowOverride All
Allow from all
</Directory>
</VirtualHost>
with ref in hosts file : 127.0.0.1 cake84.loc
the .htaccess file is present and contains:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
and I have the file /Application/XAMPP/etc/httpd.conf with the line :
LoadModule rewrite_module modules/mod_rewrite.so uncommented...
Am I forgetting something ?!!
Notice that the same configuration was working a week ago but in the parent folder. The only change I've made was to move the whole site from : /Users/me/Sites/c84 to /Users/me/Sites/c84/cakephp and then changing the path of the virtualhost. (And for sure, restarted the apache...)
Well... Problem solved...
It seems that cakephp has problems to detect correctly if the rewrite url mode is enabled...
The best way is to call an url that should be rewritten to test the url rewritting.
In my case, the url rewriting was correctly enabled although I got this message... But unfortunately, the url I called to test it, had a syntax error (typo...) that I missed and nothing was shown...
I am also on Mavericks. For me, I had to edit the file:
/private/etc/apache2/users/myusername.conf
(Replace myusername.conf with the username on your computer.)
In this file, I had to change the lines:
Options Indexes MultiViews to Options Indexes MultiViews FollowSymLinks
and
AllowOverride None to AllowOverride All,
and then restarting Apache, solved the problem.
Hope this helps anyone else Googling for a solution on Mavericks.

How do I get rid of the need for the "/app.php/" in a new Symfony2 app's production URL?

I've done a 1st install of Symfony2,
php app/console --version
Symfony version 2.0.11 - app/dev/debug
I installed it under an existing DocumentRoot by configuring my apache2 server vhost
<VirtualHost 127.0.0.1:80>
...
DocumentRoot /srv/www/localhost_www
...
<Directory "/srv/www/localhost_www" >
AllowOverride none
Options -ExecCGI +FollowSymLinks +Includes +Indexes +MultiViews
Order Allow,Deny
Allow from All
</Directory>
...
Alias /TESTAPP "/srv/www/TESTAPP/web/"
<Directory "/srv/www/TESTAPP/web/">
Options All
AllowOverride All
Allow from All
</Directory>
Alias /TESTAPP.symfony "/srv/www/TESTAPP/"
<Directory "/srv/www/TESTAPP/">
Options All
AllowOverride All
Allow from All
</Directory>
...
After an OK install, and successfully following "The Book" to build the demo "Hello" app, if I nav in a browser to any/all of,
dev:
http://localhost/TESTAPP.symfony/web/app_dev.php/hello/ME
http://localhost/TESTAPP/app_dev.php/hello/ME
prod:
http://localhost/TESTAPP.symfony/web/app.php/hello/ME
http://localhost/TESTAPP/app.php/hello/ME
I see the expected,
"Hello ME!"
I want to rewrite only the production URLs, hiding "app.php" so that the following set of URLs work in the nav bar of a browser for my Symfony2 app:
dev:
http://localhost/TESTAPP.symfony/web/app_dev.php/hello/ME
http://localhost/TESTAPP/app_dev.php/hello/ME
prod:
!! http://localhost/TESTAPP.symfony/web/hello/ME
!! http://localhost/TESTAPP/hello/ME
Iiuc, the default web/.htaccess
cat web/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
needs to change.
I've dug around in the docs and on the web, tried vdiffferent recommendations for modding the RewriteRule, adding 'RedirectMatch permanent', etc., and I'm not managing to get a simple
http://localhost/TESTAPP/hello/ME
to ever work. I always seem to need to add the "/app.php/".
What are the specific changes I'd need to make in order to get this to work?
Thanks.
#chasen
is mod_rewrite enabled for apache?
yes
if you have your .htaccess file in your web directory
i do
and you host file pointing to the web folder the
it is, as above,
Alias /TESTAPP "/srv/www/TESTAPP/web/"
<Directory "/srv/www/TESTAPP/web/">
app.php should not be needed.
that's my problem. without it, it's not working for me.
Specifically,
https://localhost/TESTAPP/app.php/hello/ME
returns:
"Hello Me!"
but
https://localhost/TESTAPP/hello/ME
returns
Object not found!
The requested URL was not found on this server.
If you entered the URL manually please check your
spelling and try again.
If you think this is a server error, please contact
the webmaster.
Error 404
i know that its a silly question but is mod_rewrite enabled for apache?
if you have your .htaccess file in your web directory and you host file pointing to the web folder the app.php should not be needed.
if you are running ubuntu or a similar distro you can do:
sudo a2enmod rewrite
sudo service apache2 reload
sudo service apache2 restart
That should enable the mod, and reload apache.
EDIT:
That response you are getting back is it in a symfony page? if it is its likely that your prod cache needs to be cleared, from the root directory for the application use the symfony console to clear the cache:
php app/console cache:clear --env="prod"
EDIT:
If neither of those have worked you may try adding a RewriteBase to the htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /TESTAPP
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
In my case I need to modify the line containing AllowOverride None to read AllowOverride All. This tells Apache that it's okay to allow .htaccess files to over-ride previous directives. You must reload Apache before this change will have an effect (https://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles):
Do this: - go to "/etc/apache2" modify file "apache2.conf" section:
<Directory /var/www/>
Options FollowSymLinks
AllowOverride All
Require all granted
restart server: /etc/apache2# service apache2 restart
it should work. If it does not work, still you have done 1 step right to insure .htaccess is allowed to override. There are many other reasons can be fixed with the above instruction.
Adding the RewriteBase rule with the name of the folder in which the project is held to the .htaccess file does it's job! Thanks!
RewriteBase /project_name

Resources