Capifony disabling the application - symfony

I'm trying to disable the website I deployed on my test server with Capifony.
The maintenance.html file goes up, everything's ok with the web:disable/enable commands.
My only problem is how to detect the maintenance file, and redirect to it using the .htaccess file provided by Symfony.
(I thought of detecting the maintenance file in the app_*.php scripts, but not only it feels hacky, it wouldn't disable access to the other files in the web/ folder.)
Any advice is greatly appreciated.

You can disable access directly by rewrite rule in your webserver config. If maintenance.html file found redirect to it, or to another static page. For Apache's htaccess it will be something like this:
RewriteCond %{DOCUMENT_ROOT}/web/maintenance.html -f
RewriteRule ^/(.+) /web/maintenance.html [QSA,L] [L,QSA]

I havn't tested it yet but the Capifony lib features this snippet:
ErrorDocument 503 /#{maintenance_basename}.html
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(css|gif|jpg|png)$
RewriteCond %{DOCUMENT_ROOT}/#{maintenance_basename}.html -f
RewriteCond %{SCRIPT_FILENAME} !#{maintenance_basename}.html
RewriteRule ^.*$ - [redirect=503,last]
https://github.com/everzet/capifony/blob/master/lib/symfony2/web.rb

Related

Can you have a conditional in the htaccess file

Been looking around the web to add a production rule in the .htaccess file. I have a wordpress website; one for production and the other, staging.
When a file is uploaded, it goes to AWS (s3). I need to prevent this behaviour for staging.
The code that sets the asset path is, in the .htaccess file:
RewriteRule ^wp-content/uploads/(.*)$ https://s3-eu-west-1.amazonaws.com/<BUCKET-NAME>/wp-content/uploads/$1 [R=301,L]
I cant seem to find an "if statement" or some sort of condition to use. Honestly, I think this is not possible. Is it?
I only need to run that code for production and not staging. Staging url is different from production.
Updated
Whenever I use below, my website crashes:
<If "-z req('Host') == 'www.<PRODUCTION>.com/'">
RewriteRule ^wp-content/uploads/(.*)$ https://s3-eu-west-1.amazonaws.com/<BUCKET-NAME>/wp-content/uploads/$1 [R=301,L]
</If>
If directive works on Apache 2.4 and newer versions. On lower versions you can use RewriteCond directive to conditionally rewrite urls.
You can use something like this
RewriteEngine on
#if host == "www.production.com"
RewriteCond %{HTTP_HOST} ^www.production.com$ [NC]
# execute the rule
RewriteRule ^wp-content/uploads/(.*)$ https: //s3-eu-west-1.amazonaws.com/<BUCKET-NAME>/wp-content/uploads/$1 [R=301,L]

Drupal returning 404 on images when not prefixed with www

I'm attempting to help a friend configure their drupal site on the latest Drupal 7 release. I am being returned 404 on some images but not others.
Works:
http://www.example.com/sites/default/files/fs_pic_sm.jpg
Doesn't work:
http://example.com/sites/default/files/fs_pic_sm.jpg
What are the configuration steps needed to serve both? I'm not familiar with Drupal so if there is pertinent information I have omitted please inform me and I'll update this question.
This could be a server setting as www.example.com and example.com are considered two different sites (www is a subdomain).
Edit your .htaccesss file in your document root and uncomment the lines:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This way they are automatically redirected to www and should no longer see the 404.

Wordpress permalink structure change issue

I have seen some other posts on SO about this issue, however none of the suggested solutions did work for me, so I repost.
After changing my permalink structure to /%postname%/, none of the links is working. I get the following 404:
Not Found
The requested URL /my-post-name/ was not found on this server.
Apache/2.2.20 (Ubuntu) Server at mysite.com Port 80
When I get back to the default permalink structure it starts to work again, but I want to have /%postname%/ structure anyways.
My .htaccess file's chmod is 777.
After updating my permalink structure to /%postname%/, the .htaccess file generated by Wordpress is the following:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any thoughts?
Edit:
I tried to change permalink structure to the following:
/index.php/%postname%/
and it happily worked. However, the problem is now, not surprisingly, the links are in the following form:
www.mysite.com/index.php/my-page.com
My question is how can I remove index.php from my links. When I remove it from the permalink structure (i.e., /%postname%/), my links no longer work.
PS: Instead of using blog entries I use only pages in my site. If it is necessary my site is: mll.sehir.edu.tr.
There are many ways how you can fix this issue, if you know the root of the issue.
Problem 1
Firstly, it may be a problem with your apache not having the mod_rewrite.c module installed or enabled.
For this reason, you would have to enable it as follows
Open up your console and type into it, this:
sudo a2enmod rewrite
Restart your apache server.
service apache2 restart
Problem 2
You may also, in addition to the above, if it does not work, have to change the override rule from the apache conf file (either apache2.conf, http.conf , or 000-default file).
Locate Directory /var/www/
Change the Override None to Override All
Problem 3
If you get an error stating rewrite module is not found, then probably your userdir module is not enabled. For this reason you need to enable it.
Type this into the console:
sudo a2enmod userdir
Then try enabling the rewrite module if still not enabled (as mentioned above).
To read further on this, you can visit this site: http://seventhsoulmountain.blogspot.com/2014/02/wordpress-permalink-ubuntu-problem-solutions.html
Sounds like a problem with symlinks on your server. Try this in your .htaccess and also please change it to 644 after making the change:
Options +FollowSymlinks
RewriteEngine on
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I had the same problem but i am using other url structure /%category%/%postname%/
The problems with de 404 error is because even if you set a certain structure, wordpress is always trying to create the urls with the word "category" on the url.
Try to type your urls like this: yoursite.com/category/postname, if you are not getting any error now is because we are close to resolving the error. Now try to install this wordpress plugin http://wordpress.org/extend/plugins/no-category-base-wpml/ to remove the "category" base from urls
Let me know about your progress
Replace and try your .htaccess with this:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^hostname.com$
RewriteRule ^(.*)$ http://www.hostname.com/$1 [R=permanent,L]
I got this issue whenever i try to enable my site's permalink to mod_rewrite: "Pretty Permalinks". My site is one instance on AWS EC2.
404 Errors
Page Not Found
The requested URL .... was not found on this server.
Apache/2.4.7 (Ubuntu) Server at mydomain.com Port 80
I tried all above methods, but not being fixed.
At last, I checked the /etc/apache2/sites-available/wordpress.conf, I found I used public IP address assigned to each instance by AWS. Once I change it to the current mydomain.com, it's working.
Sometimes, wordpress.conf would be locked by httpd (web serser), we need to stop and start it after edit. We also need to use: sudo service apache2 stop/start so as wordpress.conf could be reload again.
Hope my experience could help others.

Set up CakePHP in a subdirectory; Wordpress is installed in the root

I have been searching for a solution for 2 hours but nothing seems to work... here is my problem:
I have WordPress installed in the root (var/www). So by going to http://www.geekderek.com, I see my wordpress site.
I put CakePHP in a subdirectory var/www/cakephp. I want to be able to see my CakePHP app by going to: www.geekderek.com/cakephp.
However, currently this url just returns a Wordpress page saying "Content not found."
I believe this problem can be solved by modifying .htaccess in my root directory. So here is my .htaccess: http://pastebin.com/sXJTRstB
As you can see, I added this line to the default WP .htaccess file:
RewriteRule ^cakephp(/(.*))?$ cakephp/app/webroot/$1 [QSA,L]
However, for some reason this doesn't seem to work.
Could anyone please tell me what is wrong?? Thank you so much!
I have simmilar setup, that my cake app is in subdirectory, my root .htaccess has this rewrite rule:
RewriteRule ^cakephp/(.*)$ /cakephp/$1 [L,QSA]
All the rest is handled with the regular cakephp setup.
my /cakephp/app/webroot/.htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
hope this works for you too :)
thanat's answer almost worked for me. i just had to edit the RewriteBase to read
RewriteBase /cakephp
and make sure apache conf allowed my root directory to override its previous options
<Directory "/my/root/dir">
AllowOverride All
</Directory>
but then again, my app dir lies outside the DocumentRoot set by apache. and the cakephp dir is actually the webroot itself. so my dir structure is as follows
/my/root
/my/root/app #cake's app dir without webroot
/my/root/dir #apache DocumentRoot (your wordpress is here)
/my/root/dir/cakephp #cake's webroot
also make sure to edit /my/root/dir/cakephp/index.php so it knows where the app and cake's library dirs are.
This is my case, with laravel but they are the same.
https://community.bitnami.com/t/laravel-application-in-subdirectory-of-wordpress-website/79535/2
Just need to change
AllowOverride None => AllowOverride All

Map Domain Alias to Virtual Folder in IIS6

How could I go about mapping a domain alias, e.g. domainAlias.co.za, to a virtual folder under, e.g. mainDomain.co.za, so that all requests to domainAlias.co.za actually get served by mainDomain.co.za/domainAlias ?
A URL Rewriter like IIRF lets you do this.
The rules would be:
RewriteCond %{HTTP_HOST} ^(?!mainDomain)([^\.]+)\.co\.za$
RewriteRule ^/(.*)$ /%1/$1 [L]
In English, this rule says: if the host is NOT maindomain.co.za, but still ends in .co.za, then rewrite the URL so that it is prepended with /domainAlias/. With this rule, you get:
input output
----- ------
http://foo.co.za/a.php http://main.co.za/foo/a.php
http://foo.co.za/a.aspx?r=1 http://main.co.za/foo/a.aspx?r=1
You can also go one level further and make the rewrite conditional on the presence of the directory, something like this:
RewriteCond %{HTTP_HOST} ^(?!mainDomain)([^\.]+)\.co\.za$
RewriteCond c:\wwwroot\%1 -d
RewriteRule ^/(.*)$ /%1/$1 [L]
This says: if the host is not maindomain.co.za, AND the directory c:\wwwroot\domainAlias exists, then rewrite to prepend ....
But in that case you might instead want to do the converse - test for lack of existence of the directory - and redirect to a 404:
RewriteCond %{HTTP_HOST} ^(?!mainDomain)([^\.]+)\.co\.za$
RewriteCond c:\wwwroot\%1 !-d
RewriteRule ^/(.*)$ - [NF]
NF = 404
you can also do [F] which is a 503 (Forbidden).
IIRF works on IIS5, IIS6, or IIS7.
I haven't used it, but IIS has a URL Rewrite Module that can import Apache mod_rewrite rules. There is also a document that compares IIS URL Rewriting and ASP.NET routing. With some research, you should be able to get that working.
You can use routing.
System.Web.Routing

Resources