Apache2 config - sites-enabled, problem with RewriteRule - redirect

I have upgraded my cloud service (owncloud -> nexcloud) and now need to get rid of the string "/apps/gallery" from any link that uses it.
What I currently have in /etc/apache2/sites-enabled/000-default.conf:
Listen 80
Listen 443
<VirtualHost *:80>
ServerName ***
DocumentRoot ***
RewriteEngine on
RewriteRule ^/apps/gallery/s/.*$ /s/ [L]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerName ***
DocumentRoot ***
RewriteEngine on
RewriteRule ^/apps/gallery/s.*$ /s [L]
SSLEngine on
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/***/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/***/privkey.pem
</VirtualHost>
Rewrite rule does not work and I can't get anything from logs (error and access log)...
I'm restarting apache with sudo service apache2 restart - is it enough to load new config?
Any help would be much appreciated!
------ EDIT
Following mode_rewrite manual, I have changed rewrite part to this, but still the problem exist
RewriteEngine on
RewriteRule ^/apps/gallery(.*)$ $1 [NC,R=301]

Related

Redirect from HTTPS to HTTPS of other website

I have read some other questions which are doing almost the same stuff but I wasn't able to replicate the same.
https://serverfault.com/questions/167395/redirect-https-to-another-https
Apache HTTPS to HTTPS Redirection
(I have tried both)
When users click or enter the https:// version I want to redirect my website (which is https://website1.com) to another website (https://website2.com).
What I have achieved till now is when the user clicks on http://website1.com version of the site, they are getting redirected to https://website2.com but when https://website1.com it loads the https://website1.com, no redirection happens.
I'm using Apache HTTPD and below is my httpd.conf file entry:
<VirtualHost *:80>
ServerName website1.com
ServerAlias www.website1.com
RewriteEngine On
RewriteCond %{ENV:HTTPS} on
RewriteRule ^/?(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^(.*)$ https://website2.com/$1 [R=301,L]
RedirectPermanent / https://website2.com/
</VirtualHost>
Seems OR condition is missing for HTTP.
The following code should work, although I haven't tested it.
<VirtualHost *:80>
ServerName website1.com
ServerAlias www.website1.com
RewriteEngine On
RewriteCond %{ENV:HTTPS} [OR]
RewriteCond %{ENV:HTTP} on
RewriteRule ^/?(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^(.*)$ https://website2.com/$1 [R=301,L]
RedirectPermanent / https://website2.com/
</VirtualHost>

Can not run app using fcgi of perl Dancer

I am testing to deploy the tester example of Dancer using fcgi. But it just didn't work.
I keep getting the error message:
File does not exist: /home/tester/MyApp/public/dispatch.fcgi/
However, this app can run successfully with cgi. And I have made the changes to http.conf according to dancer's deployment manual.
Can someone pointing me to some solutions or possible reasons for this error?
below is the http.conf:
<VirtualHost *:80>
ServerName localhost
# /srv/www.example.com is the root of your
# dancer application
DocumentRoot /home/tester/MyApp/public
ServerAdmin you#example.com
<Directory "/home/tester/MyApp/public">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
AddHandler fastcgi-script .fcgi
</Directory>
ScriptAlias / /home/tester/MyApp/public/dispatch.fcgi/
ErrorLog /var/log/apache2/MyApp-error.log
CustomLog /var/log/apache2/MyApp-access_log common
</VirtualHost>
Thank you
I don't think that ScriptAlias is what you want to be using. From the documentation...
The ScriptAlias directive has the same behavior as the Alias
directive, except that in addition it marks the target directory as
containing CGI scripts that will be processed by mod_cgi's cgi-script
handler.
Basically Apache looks for a directory called '/home/tester/MyApp/public/dispatch.fcgi/' and every file in this dir is processed through mod_cgi. In this case it can't be found since it's a regular file.
Have you tried using mod_rewrite? My httpd config for Dancer is pretty much the same as yours except I'm using mod_rewrite
DocumentRoot /home/user/src/MyApp/public
<Directory "/home/user/src/MyApp/public">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
AddHandler fcgid-script .fcgi #using fcgid instead of fastcgi
</Directory>
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dispatch.fcgi$1 [QSA,L]

Mod rewrite virtual host and Zend

My Apache config:
DocumentRoot /var/www
<VirtualHost *:80>
Alias /T "/var/www/Test"
<Directory /var/www/Test>
Options Indexes FollowSymLinks MultiViews
#AllowOverride ALL
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
SetEnv APPLICATION_ENV "development"
Alias /N "/var/www/NCAA/public"
<Directory /var/www/NCAA/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
My .htacess file in /var/www/NCAA/public:
RewriteEngine On
RewriteBase /N/
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I can go to files in localhost/T, but I get 404 for /localhost/N I get this in my apache log:
[Sun Nov 20 16:32:37 2011] [error] [client 127.0.0.1] File does not exist: /var/www/N,
so I'm not sure what I am doing wrong. I want 1 domain to be a regular domain with an alias and the other is a Zend app with a mod rewrute for the index.php
Thanks
Do you really need the NCAA app to be accessed under http://localhost/N? Is it acceptable to access it under a different url, like http://local.ncaa/?
If so, then a virtual host entry could look like:
<VirtualHost *:80>
DocumentRoot /var/www/NCAA/public
ServerName local.ncaa
SetEnv APPLICATION_ENV development
<Directory /var/www/NCAA/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Then the standard ZF .htaccess can be used (no rewrite base required):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

apache2: how to find out why I get a 403 error?

That is from the apache error_log:
[Mon Oct 17 17:55:42 2011] [error] [client 127.0.0.1] (13)Permission denied: access to /index.html denied
In /etc/apache2/vhosts.d I've created this file:
<VirtualHost 127.0.0.1:3000>
DocumentRoot "/home/mm/lib/vokabeltrainer"
ServerName localhost:3000
<Directory "/home/mm/lib/vokabeltrainer">
Options FollowSymLinks ExecCGI
AddHandler cgi-script .pl
IndexIgnore *
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/public/%{REQUEST_URI} -f
RewriteRule ^(.*) public/$1 [L]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
RewriteRule ^(.*) vokabeltrainer.pl [L]
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
The /etc/apache2/listen.conf looks like this:
Listen 127.0.0.1:3000
NameVirtualHost 127.0.0.1:3000
For testing, I've modified the folder like chmod -R 0777 /home/mm/lib/vokabeltrainer
When I run the vokabeltrainer.pl (Mojolicious::Lite script) with morbo development server it works.
Has somebody a clue where I should look?
As Ikegami pointed out, my first problem was that I didn't consider the /home/mm/lib part of the path: the lib-directory didn't have enough rights so I had to ad the needed rights.
Then I changed the path in the shebang form /usr/local/bin/perl to /usr/bin/perl and installed Mojolicious::Lite for the /usr/bin/perl.
The last thing I had to do, was writing the url like this http://localhost:3000/vokabeltrainer.pl/random instead of http://localhost:3000/random.
(In the Pretty "Web 2.0" URLs at mojo/wiki/Apache-deployment is shown a way to keep the short url)

404 error for mod_rewrite using SSL and MAMP

I am building an app in Zend Framework at the moment and testing it all locally. I have Mamp Pro as my web server and I have a self-signed SSL which all seems to work. My problem comes when I try to do mod_rewrite - I just get 404 pages.
The way I have things set up (which may not be the best way...)
In Mamp I have 2 virtualhosts set up both pointing to the same web directory (webroot/public/):
secure.myapp.com
myapp.com
In my public directory is my index.php file and my .htaccess file. The contents of the .htaccess file are:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
When I visit http://myapp.com everything routes as it should using the mod_rewrite. But when I go to https://secure.myapp.com the index page is fine, but URL routing stops working and it appears to be that the .htaccess file is being ignored.
In my ssl.conf I have the following:
<IfModule mod_ssl.c>
Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
SSLPassPhraseDialog builtin
SSLSessionCache dbm:/Applications/MAMP/logs/ssl_scache
SSLSessionCacheTimeout 300
SSLMutex file:/Applications/MAMP/logs/ssl_mutex
<VirtualHost _default_:443>
SSLEngine on
DocumentRoot "/webroot/public"
ServerName secure.myapp.com
ServerAdmin you#example.com
ErrorLog /Applications/MAMP/logs/ssl_error_log
TransferLog /Applications/MAMP/logs/ssl_access_log
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /Applications/MAMP/conf/apache/ssl_cert/server.crt
SSLCertificateKeyFile /Applications/MAMP/conf/apache/ssl_key/server.key
CustomLog /Applications/MAMP/logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
</IfModule>
Does anybody have any ideas on this? I'll be sooooo appreciative of the help as it's seriously hindering my development!
Well I'm pretty sure that I have got this working. Basically, a big problem I had is that Mamp does not store vhosts.conf as an accessible file. Instead this is an aliased application file.
I think what happens is that the virtualhosts are all dynamically created all on the standard http port, in my case 80. However I needed to be able to access the port 433 vhost config to enable FileInfo. So my workaround is to ditch my .htaccess file and stick the following ALL into my ssl.conf file.
<IfModule mod_ssl.c>
Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
SSLPassPhraseDialog builtin
SSLSessionCache dbm:/Applications/MAMP/logs/ssl_scache
SSLSessionCacheTimeout 300
SSLMutex file:/Applications/MAMP/logs/ssl_mutex
<VirtualHost mysite.com:443>
SSLEngine on
DocumentRoot /webroot/secure
ServerName mysite.com
ServerAdmin you#example.com
ErrorLog /Applications/MAMP/logs/ssl_error_log
TransferLog /Applications/MAMP/logs/ssl_access_log
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /Applications/MAMP/conf/apache/ssl_cert/server.crt
SSLCertificateKeyFile /Applications/MAMP/conf/apache/ssl_key/server.key
CustomLog /Applications/MAMP/logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -s [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -l [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
RewriteLog /Applications/MAMP/logs/ssl_rewrite_log
RewriteLogLevel 3
</IfModule>
</VirtualHost>
</IfModule>
I had to add DOCUMENT_ROOT in front of my file and directory checks, and a forward slash in front of index.php. If I could have put this into a "Directory" then I think I could have avoided these changes, but Apache won't restart when I add this parameter.
The only thing I didn't try was adding the info to MAMP's httpd.conf, but I have a feeling the same restrictions may be in place.