How can I change the directory a relative path points to in apache? - mod-rewrite

I have a website running on an apache2 server and serving out of a user directory. The URL looks like this: http://example.com/~user1
This serves up files on my server located at /home/user1. The problem that I am facing is that a lot of the asset URLs throughout the site are put into the HTML as relative paths like this: <img src="/images/example.png" alt="" />
This is attempting to load the image from http://example.com/images/example.png, but I actually want it to serve from http://example.com/~user1/images/example.png.
How can I accomplish this?

/images/example.png
This is a root-relative, not a relative URL-path.
This is attempting to load the image from http://example.com/images/example.png, but I actually want it to serve from http://example.com/~user1/images/example.png.
This is a client-side/browser URL resolution issue. There are no "switches" on the server that can be applied to change this behaviour, without changing the actual URLs.
This is an inherent problem with using Apache per-user web directories.
Your options are:
Don't use Apache per-user web directories. ie. Remove /~<user1>/ from the URL.
Or,
Use relative URL-paths to your assets. eg. images/example.png (no slash prefix). So the browser correctly resolves this as /~user1/images/example.png instead (when accessed from the document root at least). But this creates additional problems if you are rewriting the URL of your pages at different path depths or using common templates in your pages etc.

Related

How to run Multiple codeigniter application in single shared hosting server?

I am using shared hosing for Codeigniter application for deployment.
How can i run staging url on live server?
1) domain.com (Working)
2) domain.com/staging/ (Not working, showing 404 error)
I created staging folder under public_html directory, now put All CI code in staging folder, and tried to run the application with URL domain.com/staging/ but it redirect on domain.com/404
I expect to run domain.com for users and domain.com/staging for development. (Staging URL i will use for development and after that i will place the same code for live URL.)
This is most easily done by using a subdomain for the staging version, i.e. staging.doman.com. The folder where you put the CI files isn't super important as the subdomain will be set to use the directory you choose.
You will either need to have complete control over the server or have a service provider that allows you to set up subdomains.
- Expanded Answer -
If you cannot set up a subdomain then your next best option is to use the advice in the documentation on Managing you Applications. It isn't required to use the file structure shown there. In your case try the following.
Create a folder on the same level as application named staging.
Into that folder copy all the folders and files normally found in /application.
Add all application folders and files required by your site. The files in these folders are those that make up the application you are staging.
Make a copy of index.php (the file at the root of the public folder, i.e. domain.com/index.php) and name it staging.php. Both index.php and staging.php will be in the same folder.
Edit staging.php and change the value of $application_folder to be the absolute path to the staging folder. For example:
$application_folder = '/path/to/domain.com/public_folder/staging';
The path above is an example. You must replace it with the actual path in your server. If you have no idea what the full and absolute path is you can use
$application_folder = dirname(__FILE__).'/staging';
Browse to the URL domain.com/staging.php and you should get your default controller's output. To test that you are actually seeing the staging version of the page temporarily change something in the view file so there can be no doubt.
You will go to other controllers by using the URL domain.com/staging.php/other_controller.
Change the value of $config['index_page'] in /staging/config/config.php to staging.php, e.g.
$config['index_page'] = 'staging.php';
Without the above change redirect() and many other "helper" functions will not work correctly.
(Optional?) You can probably edit the main .htaccess and add rewrite rules for staging.php the same way it is done for index.php. But I will leave that as an exercise for you. (Or for another SO question.)
A final word. It might be necessary to make other configuration changes to accommodate the revised file structure. I tested the answer here but did not go beyond the most basic task of browsing to controllers. Most likely config values for sessions, cookies, and many others will need to be adjusted for the staged version to work correctly. Check out the documentation on Handling Multiple Environments for guidance on making this less painful.

Laravel website behind the reverse proxy and subfolder?

I have a Laravel website with LAMP stack and host on a ec2 server. I setup the Virtual Host configuration for the host name www.abc.com and it works fine. One day, The client said they want to use their domain to visit the website like www.client.com/abc. They use the reverse proxy to point our ec2 server. The first problem we met is the virtual host has failed and we fixed it by adding server alias setting.
ServerAlias www.client.com
The url has connected to the server correctly and the second problem is coming up. Because of the subfolder of the url www.client.com/abc, all the assets paths are failed. For example, we had fonts, styles and js paths that generated by laravel-mix:
{
"/js/app.js": "/js/app.js",
"/css/app.css": "/css/app.css",
"/js/login.js": "/js/login.js"
}
Those paths are absolute and it turns to 404 found on the website if we use the mix() helper function to load assets. The rendered url on the blade pages are wrong.
It would be
http://www.client.com/js/app.js
instead of
http://www.client.com/abc/js/app.js
And the fonts loaded from the vendor and styles, which use the relative paths and are converted to absolute as well. So we had to workaround this by adding the option processCssUrls: false to webpack.mix.js.
The third problem is the redirection when user logs in out. The defaults redirect url is /. I know we can change the redirect urls in middleware and controllers but it feels like so much workaround over this. Is there any better way to solve those problems?
To declare the question again, how to setup a Laravel project behind the reverse proxy with subfolder?
http://www.example.com/laravel

How to fix the URL triangle lock for Magento website?

How can I fix this issue. I am using Magento.
Click here to the Website Link
All your resource and image path must be replace with https I have found on your site like link http://www.trenpon.com/ all link and images and file path link change to https.
The code in your home page has 93 instances where you have hard-coded http:// in the URL. There are 41 instances with the https:// prefix. While not all cause the mixed content warning, there are several that are resources served over http. You can go to the console in most modern browsers and see the resources that are causing the warning.
Here are some options:
Use relative URLs for your internal resources.
Use URLs without a scheme (http: or https:).
Code everything to use HTTPs.

CodeIgniter How to create Multiple Site with One CMS

I want to create a blog site with only one CMS. This CMS will be in different domain.
For example: mycms.com
Then my blog sites are also in different domains.
For example: website1.com, website2.com, website3.com
They will all use mycms.com as their admin
*Images will be uploaded in mycms.com/images/ so all the 3 websites will get the images from this directory
If images are loaded on website1.com from the main database, they should be displayed as if they're from website1.com. So for example website1.com/images/cat.jpg instead of mycms.com/images/cat.jpg
How will I build this using codeigniter?
You can use the same CodeIgniter /System and /Application folders for all the websites if you like; just make sure all the index.php files are setup to use those same folders for $system_path and $application_folder respectively. Note that these sites also need to reside on the same server.
You can serve up different content by checking $_SERVER['HTTP_HOST'] for the domain the request came from.
As for htaccess you should be able to use %{HTTP_HOST}/$1 or %{HTTP_HOST}$1 (depending on server config) to make the rewrite rule dynamic.
I am actually building a similar project right now using CodeIgniter but there are also several other projects available like halogy, codefight, pyro (with an extension), and many others.
CodeIgniter has a System and an Application folder. You could have one global system folder and then one application folder for each of your subdomains, or you could have one application folder and just make your subdomian folders parallel with your www folder.

Wildcard has no effect in IIS7 URL rewrite

I have a webapp that on my local machine runs as the root url, however on the server it runs in new virtual directory of another website.
The problem I have is that all the images have been written like so;
<img src="/Images/image.jpg" .../>
However when I upload the webapp to the server the image needs to be like this
<img src="/myApp/Images/image.jpg .../>
So I thought I would use the rewrite module to change the image path and save myself some time. Using IIS7 I have the following for the pattern;
*/Images/*
and this for the actions rewrite property
http://example.com/myApp/Images/{R:2}
However it doesn't work - this image is still showing as not found. Would someone point out my mistake?
The pattern ought to be a regular expression, try match as
^.*?/Images/(.*)
and the rewrite url as
/myApp/Images/{R:1}
Note this needs to be in the web.config for the site not the application.

Resources