How to apply Apache RewriteRule only on my NAS? - apache

I am developing a website, so i am using to develop, my NAS and i send it to official server when is OK.
So on my NAS, the website is on folder called "Multi-Plateform" (and i have some other folder in my NAS)
To do work it I found a rule for htaccess file in my website folder :
RewriteRule !^Multi-Plateform/ Multi-Plateform%{REQUEST_URI}
But this RewriteRule is creating a falldown of my site in the official server.
So how to apply the rules only when in my NAS ?
I tried : "Directory", "Location", "LocationMatch" but is not the solution for the official server.

Related

Redirecting as proxy one subfolder of apache server to azure web app

I have a website on apache web server, and I would like one of subfolders to transparently redirect to azure web app.
mydomain.org -> regular apache page
mydomain.org/something -> regular apache page
mydomain.org/azure -> redirect to azure
However, I would need the url to stay on mydomain.org, so I would like - for example mydomain.com/azure/x/y to actually show result of azuredomain.org/x/y
I believe I can do it using .htaccess with rule: RewriteRule ^(.*)$ azuredomain.org/$1 [P]
However, this results in azure 404 error with suggestion that maybe "Custom domain has not been configured inside Azure", which is in fact correct.
Is it possible to configure 'mydomain.org ' as custom domain in azure, but only for one subfolder (mydomain.org /azure/) while allowing all other urls to map to apache server?
I managed to make it work:
Create subdomain 'azure' pointing to folder 'azure'
Add .htaccess to 'azure' folder with rule RewriteRule ^(.*)$ azuredomain.org/$1 [P]
Add records to domain:
TXT / asuid.azure / [verificationID]
CNAME / azure / azuredomain.org
In Web App settings add custom domain with subdomain: azure.mydomain.org

Laravel | Shared hosting routes not working properly

I am trying to deploy my Laravel project on a shared host(godaddy) and so far I have only partially succeeded.
Steps I followed:
Create a subdomain abc.xyz.com , root -> public_html/finance/.
Upload my laravel project to a folder which is at same level as that of public_html
softlink the public directory of my project to public_html/finance/
I found that going to abc.xyz.com didn't work but abc.xyz.com/public did so I set up a redirect which redirects abc.xyz.com to abc.xyz.com
making Storage accessible for web.
dumpautoload, caching config and routes.
migarting databases.
Now I can successfully login which takes me to abc.xyz.com/public but my all other routes which does not have /public do not work.
For example:
abc.xyz.com/public - works
abc.xyz.com/home - doesn't work
I noticed that if I manually add /public to all routes they work!. so abc.xyz.com/public/home works.
my .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
So how can append /public like abc.xyz.com/public to all the routes?
I am not very good at modifying .htaccess but I tried some solutions from online and they did not work.
Excerpted from Deploy Laravel 5 App on Shared Hosting on Linux Server. The original authors were Donkarnash, PassionInfinite, Pete Houston and Kyslik. Attribution details can be found on the contributor page. The source is licenced under CC BY-SA 3.0 and may be found in the Documentation archive. Reference topic ID: 2410.
By default Laravel project's public folder exposes the content of the app which can be requested from anywhere by anyone, the rest of the app code is invisible or inaccessible to anyone without proper permissions.
After developing the application on your development machine, it needs to be pushed to a production server so that it can be accessed through the internet from anywhere - right?
For most apps/websites the first choice is to use shared hosting package from hosting service providers like GoDaddy, HostGator etc. mainly due to low cost.
note: you may ask your provider to manually change document_root, so all you have to do is upload your Laravel application to server (via FTP), request change of root to {app}/public and you should be good.
Such shared hosting packages, however do have limitations in terms of terminal access and file permissions. By default one has to upload their app/code to the public_html folder on their shared hosting account.
So if you want to upload a Laravel project to a shared hosting account how would you go about it? Should you upload the entire app (folder) to the public_html folder on your shared hosting account? - Certainly NO
Because everything in the public_html folder is accessible "publically i.e. by anyone" which would be a big security risk.
Steps to upload a project to shared hosting account - the Laravel way
Step 1
Create a folder called laravel (or anything you like) on the same level as the public_html folder.
Eg:
/
|--var
|---www
|----laravel //create this folder in your shared hosting account
|----public_html
|----log
Step 2
Copy every thing except the public folder from your laravel project (on development machine) in the laravel folder (on server host - shared hosting account).
You can use:
- C-panel : which would be the slowest option
- FTP Client: like FileZilla to connect to you shared hosting account and transfer your files and folders through FTP upload
- Map Network Drive: you can also create a mapped network drive on your development machine to connect to your shared hosting account's root folder using "ftp://your-domain-name" as the network address.
Step 3
Open the public folder of your laravel project (on development machine), copy everything and paste in the public_html folder (on server host - shared hosting account).
Step 4
Now open the index.php file in the public_html folder on the shared hosting account (in cpanel editor or any other connected editor) and:
Change:
require __DIR__.'/../bootstrap/autoload.php';
To:
require __DIR__.'/../laravel/bootstrap/autoload.php';
And Change:
$app = require_once __DIR__.'/../bootstrap/app.php';
To:
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
Save and close.
Step 5
Now go to the laravel folder (on shared hosting account -server) and open server.php file
Change
require_once __DIR__.'/public/index.php';
To:
require_once __DIR__.'../public_html/index.php';
Save and close.
Step 6
Set file permissions for the laravel/storage folder (recursively) and all files, sub-folders and file within them on shared hosting account - server to 777.
Note: Be careful with the file permissions in linux, they are like double edged sword, if not used correctly, they may make your app vulnerable to attacks. For understanding Linux file permissions you can read https://www.linux.com/learn/tutorials/309527-understanding-linux-file-permissions
Step 7
As .env file of local/development server is Ignored by git and it should be ignored as it has all the environment variables including the APP_KEY and it should not be exposed to public by pushing it into the repositories'. You can also see that .gitignore file has .env mentioned thus it will not upload it to repositories.
After following all the above steps make a .env file in the laravel folder and add all the environment variable which you have used from the local/development server's .env file to the .env file of production server.
Even there are configuration files like app.php, database.php in config folder of laravel application which defines this variables as by default in second parameter of env() but don't hard-code the values in these files as it will affect the configuration files of the users who pulls your repository. So it is recommended to create .env file manually!
Also laravel gives .env-example file that you can use as a reference.
That's it.
Now when you visit the url which you configured as the domain with your server, your laravel app should work just as it worked on your localhost - development machine, while still the application code is safe and not accessible by anyone without proper file permissions.
You can probably move your public/.htaccess and public/index.php to the root files of your laravel project.
You need to change the document root for you website to be the public folder of your application i.e.
public_html/finance/.
should be:
public_html/finance/public
https://laravel.com/docs/5.4/installation#configuration
Hope this helps!
The problem is that you have placed the entire project in the public directory - public_html, haven't you? This is a bad practice (security).
Your domain (abc.xyz.com) points to your application root directory, should go to the app/public dir.
Update Solution: require DIR.'/../bootstrap/autoload.php';
Is now: require DIR.'/../vendor/autoload.php';
So Change To require __DIR__.'/../laravel/vendor/autoload.php';
In addition to pointing to the correct files and folders, add the below .htaccess file. Credit - Kylevorster
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

OpenShift and Jekyll Cartridge Force SSL

I'm using an application on OpenShift started from the Jekyll Cartridge, but running octopress on top (I suppose that's the same difference).
I would like to automatically redirect all HTTP requests to HTTPS. So that it can only be viewed over HTTPS.
I don't see a way to do this with Jekyll served on OpenShift, using the cartridge. I can do it locally, by modifying my config.ru file but that has no effect on OpenShift. Is there a way to force this on my application?
If your app is served by apache, you can try to put an .htaccess file at you root, containing :
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
from openshift kb
I managed to solve the issue, I'm not too happy with it as a "solution", but it works so I'm posting it.
The Jekyll cartridge seemed to be using WEBrick as the webserver, and I couldn't get control over it well enough to make it enforce SSL.
Basically I made a new application based on the "Ruby 1.9" cartridge, instead of the Jekyll cartridge. This gave me an apache hosted application. I then had to put use the .htaccess file as suggested by David earlier, in the source (!) folder of my octopress blog:
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
That did the trick. I don't think it's an ideal solution though, so all better solutions are welcome.
Here's everything I did in detail to move from the Jekyll cartridge to the Ruby 1.9 Cartridge:
Make a new openshift application, using the Ruby 1.9 Cartridge
Clone the new openshift application's git repo to a local folder
Copy all the files from the original repository to this new repository
Re-generate using Jekyll (rake generate)
Add and commit everything
Then push to openshift (this should result in a blog working as before)
Merge with github repo (git pull )
Add github as a remote (and deal with some minor conflicts)
Now I can work in my repo and perform "git push" (to openshift) and "git push ".
To force SSL:
Create an .htaccess file in the "source" folder of my octopress blog and re-generate.
Note: Now I have to make sure to do "rake generate" before I push to openshift (although I guess I could automate that on openshift after an update).

Redirect files by extension with htaccess

I have a site hosted in a Windows Server that contains a WP install and a bunch of custom ASP pages. I have to move the whole site to a new Linux host and the ASP pages to a subdomain in a Windows Server.
I need a .htaccess script to redirect the *.asp files to a subdomain, for example, http://www.domain.com/pagex.asp?id=12345 to http://windows.domain.com/pagex.asp?id=12345
Thanks in advance
RewriteEngine On
RewriteRule ^/?(.+\.asp)$ http://windows.domain.com/$1 [L,R=301]
You can test your rules here:
htaccess tester
I tested the above rule with your example url (http://www.domain.com/pagex.asp?id=12345), and it returned your example result (http://windows.domain.com/pagex.asp?id=12345).

Tricky wordpress setup with redirect from another server

I could use some advice as to how to migrate from my local staging server to my production server. Its a rather tricky setup so bare with my as I try to describe it.
I have my site set up and working great at the root of a staging subdomain on my personal server.
Staging: staging.mydomain.com
later this week I'm going to be moving it to a new production server on Rackspace which currently has no domains attached to it (is just an IP address). The clients is redirecting a folder to the new rackspace server.
http://www.clientsdomain.com/subfolder/
This will be where the site lives. But clientsdomain.com is a different server somewhere else in the world (not at rackspace). they will be redirecting traffic to that url to the new rackspace server.
So my questions are:
my working staging set up for wordpress is at the root of my personal servers subdomain. How should I set it up on rackspace? At the root of the ip address? or within a subfolder to mimic the domain setup for any relative links.
The reason I ask is that I thought i had this set up properly....But...
I went ahead and attempted to move the site onto my Rackspace server into a dev folder. My client set up a dev url
http://www.clientsdomain.com/dev/subfolder/
Anyone visiting that url will get redirected to my server (my rackspace server simply has an ip address)
the sites front end works with absolute urls. But where things start to fail is within wp-admin. If for example i'm on the General Settings page and click save. It saves the data and then redirects to /wp-admin/... instead of /dev/subfolder/wp-admin/. Since that folder doesn't exist it goes to my clients 404 page.
Also, going to
http://www.clientsdomain.com/dev/subfolder/wp-admin ends on the clients servers 404 page but...
http://www.clientsdomain.com/dev/subfolder/wp-admin/ (with slash) works properly.
The way I moved the site to Rackspace from my dev folder was to change the URLs in wp-admin on my server (which was staging.mydomain.com) to
http://www.clientsdomain.com/dev/subfolder/
I then saved those settings, downloaded the db and site files and uploaded the files and database to rackspace and changed the wp-config file to match the rackspace db.
This is my current htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I would REALLY appreciated some guidance here. supposed to be going live on Tuesday.
Thanks!
Fish
I recently setup a WordPress installation on a standard domain (www.domain.com) but had to move it over to another domain which had a subdomain (blog.newdomain.com). I found I was experiencing very similar problems to you, especially with wp-admin redirecting to the previous domain which no longer existed.
I came across a handy search and replace tool for MySQL databases (available at http://interconnectit.com/124/search-and-replace-for-wordpress-databases/) and replaced all instances of the original www.domain.com with the new blog.newdomain.com and it corrected all my issues.
I hope this information will help you.
It's usually the options table that causes the issue. Executing
update wp_options set option_value = replace(option_value, 'old_url', 'new_url');
As direct SQL on the DB should do the trick (replacing old_url and new_url with the correct urls).
Another path would be to define these two WP constants in your wp-config.php file, which will override the DB setting for the site URLs:
define('WP_HOME','http://sitehomeurl');
define('WP_SITEURL','http://siteurl');
And of course the caveat to back up your DB before running SQL against it applies.