change Apache document root in XAMPP - apache

I have just downloaded a website which contains static html pages from a hosting to my localhost (XAMPP) and saved it to a subdirectory in XAMPP htdocs directory.
When I view the local website in browser, all css, js files and images were missing. I checked the HTML source code and saw that it's all using relative path for css/js or href link. For example:
Text Link
It works on the hosting, but on my localhost, it points to http://localhost/contact instead of http://localhost/bf/contact (my subdirectory name is bf). This structure is applied to all css, js files too and they could not be loaded.
I have tried to add .htaccess file to my subdirectory:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !bf/
RewriteRule (.*) /bf/$1 [L]
But it still not works. I don't want to manually change all src, href, and link in every HTML pages to fix this. There would be a way to make Apache recognize the root is /bf instead of / , applied to all files in this directory only. Please help !
Thank you very much !

You can get this work by setting apache virtual host at locally as describe below:
For example in ubuntu /etc/apache2/httpd.conf,
If you are using XAMPP on window that is the case, then the httpd.conf file should be C:\xampp\apache\conf\httpd.conf.
Please follow below steps to configure your local sites at local server:
------------
Step 1
------------
i.e
<VirtualHost *:80>
ServerName test.demo.tst ( Any name you want to set )
DocumentRoot "C:/xampp/htdocs/bf"
<Directory "C:/xampp/htdocs/bf">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
#RackEnv development
ErrorLog C:/xampp/htdocs/bf/logs/test.demo.tst_error
CustomLog C:/xampp/htdocs/bf/logs/test.demo.tst_access common
</VirtualHost>
------------
Step 2
------------
Than you need to restart apache service
------------
Step 3
------------
Than you need to do setting in your hosts files
for example in hosts file place below entry
127.0.0.1 test.demo.tst
------------
Step 4
------------
Than you can access this url test.demo.tst local server.
I hope this informations would be helpful to you.

Please try this one..
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !bf/
RewriteRule ^(.*)$ /bf/$1 [QSA,L]
Hope this is helpful to you. And your apache rewrite mode must be on in php.ini

Related

Apache subdomain vhost + subfolders of several Magento 2 installs

Basically I want to have several stores under one subdomain as sub-folders. Like this:
mysubdomain.website.com/magento2v1 - Magento 2 store #1
mysubdomain.website.com/magento2v2 - Magento 2 store #2
mysubdomain.website.com/magento2v3 - Magento 2 store #3
Steps that I did:
This subdomain will be run in a VPS server so first I needed to redirect the subdomain (mysubdomain.website.com, the one above) to another IP (the actual VPS server) using an A record.
Second I created a Vhost with the mysubdomain.website.com on that VPS server
This is the vhost on the VPS server, Apache2:
<VirtualHost *:80>
RewriteEngine On
ServerName mysubdomain.website.com
ServerAlias www.mysubdomain.website.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/mysubdomain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And then in /var/www/mysubdomain I have:
/var/www/mysubdomain/magentov1
/var/www/mysubdomain/magentov2
/var/www/mysubdomain/magentov3
Now the problem is, Magento 2 needs .htaccess redirects where it redirects /pub to the actual sub-folder. I can't seem to get these .htaccess to work. The htaccess is read but it seems like the folders go a little bit crazy.
/var/www/mysubdomain/magentov1/.htaccess
/var/www/mysubdomain/magentov2/.htaccess
/var/www/mysubdomain/magentov3/.htaccess
Here's an example of this .htaccess:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/pub/
RewriteCond %{REQUEST_URI} !^/setup/
RewriteCond %{REQUEST_URI} !^/update/
RewriteCond %{REQUEST_URI} !^/dev/
RewriteRule .* /pub/$0 [L]
DirectoryIndex index.php
Can anybody help me get this .htaccess to work? I think it's related to the folder structure, the folder base, but I don't know how to do this and didn't found any other example.
Thank you very much!
The issue most likely is that you rewrite to the absolute path /pub/ from within the configuration files in the subfolders. How should that rewritten request be processed? After that rewriting step it appears to the next round of rewriting like a request to https://sub.example.com/pub/........ None of your existing configuration files will get applied to that. And it most likely will lead to a http status 404. Which you should be able to see in your http server's error log file and also in your browser's console network tab.
Instead you should rewrite to the relative path pub/instead. Which would result in the next rewriting step getting applied to the request to https://sub.example.com/magentov2/pub/........ Which would again get (correctly) served from within that subfolder.
In general you should try to keep global rewriting rules in a common place instead of doubling them in various parallel configuration files. Even better than a common distributed configuration file (".htaccess") in the http hosts DOCUMENT_ROOT folder would be to implement such rule in the actual central configuration file. That is faster, more robust, more secure and easier to debug.

How to make the Website run Index.html file using .htaccess?

I am trying to run a index.html file automaticlly once clicking on the folder on the Website using .htaccess
code:
RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteRule ^$ /index.html [R,L]
and then i restarted apache and refreshed the website but the folder disappeared. i try to wrote the whole link in the Url then comes (Internal Server Error)
i have here centOS 7 as Operating system runing apache
thanks for helping me and excuse please my english :D
best regards
Jackob
Yeah it works (:
Adding the following to my httpd.conf (if you have access to it) is considered better form, causes less server overhead and has the exact same effect:
<Directory /myDirectory>
DirectoryIndex index.html
</Directory>

Rewrite image directory to another folder in server using htaccess

I have images in
/home/crawler/scrapers/images/website
for example
/home/crawler/scrapers/images/website/1/img-name.jpg
My Apache root is at
/var/www/html
I have .htaccess in this folder with following content
RewriteEngine On
RewriteRule ^/images/(.*)$ /home/crawler/scrapers/images/$1 [R,L]
My goal is to show images from the images folder as I mentioned above.
http://website.com/images/website/1/img-name.jpg >> /home/crawler/scrapers/images/website/1/img-name.jpg
Currently I am getting
Not Found
The requested URL /home/crawler/scrapers/images/website/1/img-name.jpg was not found on this server.
Apache/2.4.18 (Ubuntu) Server at IP Port 80
PS: I confirm that hataccess is enabled.
You can use Alias directive for this.
Include following code in your vhosts.conf or httpd.conf and restart Apache.
Alias /images /home/crawler/scrapers/images
<Directory /home/crawler/scrapers/images>
Allow from all
</Directory>

Laravel 5 pages are not being displayed on live server

Main Points:
- I am using Laravel 5, apache, and ubuntu
- mysite.com is WORKING
- mysite.com/login works on localhost, but not on live server
I'm building my first website, and my home page is 'live' (it is up and working) My problems arise when I want to create a 'mywebsite/login' page. I am getting a 404 Not Found error on live, when the page works on my local machine.
I believe this is happening because my .htaccess file not rewriting correctly in regards to my folder structure. The problem is I'm not able to figure it out, as this is all new to me.
My document root is /var/www/laravel/public
My .htaccess is in the above folder.
It looks like this
<IfModule mod_rewrite.c>
<IfModule mod_negotians.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I have a virtual host file for my site in /etc/apache2/sites-available
It's contents look like this
<VirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/laravel/public
<Directory /var/www/laravel/public>
Options -Indexes +IncludesNOEXEC +FollowSymLinks +ExecCGI
Allow from all
Allowoverride All
</Directory>
RewriteEngine on
<Directory /var/www/laravel>
AllowOverride All
</Directory>
**A few more lines...**
</VirtualHost>
I have also enabled mod_rewrite on the server.
I am thinking that I have a smaller 'pointing' error here somewhere, but I'm not experienced enough with these files to see it. Is there anyone that can give me a hand?
Thanks
Move All the files on xyz(your folder name for which domain/ subdomain is mapped) folder
Then follow these steps
1 – go to public folder
2 – copy .htacsses file(this make your routes work)
3 -paste it in xyz folder
4 change server.php to index.php
5 – enjoy and happy coding
This is working fine with hostgator.in shared hosting.
When you push your code from local to server then sometimes it's not working the same. For that please try following commands. It works for me and I hope it works for everyone as well.
$ sudo chmod 777 -R folderpath //To give 777 permission to your project
$ php artisan config:clear //To remove the configuration cache
$ php artisan view:clear //To remove the views blade cache
$ php artisan route:clear //To remove the route cache
$ php artisan clear-compiled //To clear the compiled classes and services application cache
// If you use passport then:
$ php artisan passport:install
// At last:
$ composer update

Running magento on other port than default 80

I have configured Apache virtual hosting on port 8080 to point to my magento website.
Listen 8080
<VirtualHost 6x.2x.6x.1x:8080>
ServerAdmin webmaster#localhost
ServerName domainname.com
ServerAlias *.domainname.com
DocumentRoot /var/www/sites/domain/
<Directory />
Options FollowSymLinks
AllowOverride all
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
<LocationMatch ".*\svn.*">
Order allow,deny
Deny from all
</LocationMatch>
</VirtualHost>
When i go to the website www.domain.com:8080 the js, css, img and other things are not loaded because the port is not attached to the links
Here is a rewrite rule in magento .htaccess that does not seem to work:
<IfModule mod_rewrite.c>
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
############################################
## you can put here your magento root folder
## path relative to web root
#RewriteBase /magento/
############################################
## workaround for HTTP authorization
## in CGI environment
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
############################################
## always send 404 on missing files in these folders
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
############################################
## never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
############################################
## rewrite everything else to index.php
RewriteCond %{SERVER_PORT} !^8080$
RewriteRule .* http://6x.2x.6x.1x:8080/index.php [L]
</IfModule>
Is Rewrite-mod the right solution to run magento site on different port? If yes, where is my mistake in the current Rewrite rule?
thank you,
Margots
I manage a magento site where a live shop is running on one server on port 80 and a dev site is running on another server on port 3000. When copying the site from live to dev all I need to do is change two rows in the core_config_data table, having:
path="web/unsecure/base_url"
path="web/secure/base_url"
You need to add your port number at the end of the url and that is all. In my case those two rows look like this:
(config_id, scope, scope_id, path,
value)
(default, 0, web/unsecure/base_url,
,http://www.dev-server.com:3000/)
(default, 0, web/secure/base_url,
,http://www.dev-server.com:3000/)
Note that I don't have a certificate on my dev server so I am not using https as the secure base_url. If you wish to use https this setting should be changed to https and you should omitt the custom port at the end.
Modification of the standard .htaccess file is not needed, and should probably be avoided.
EDIT
If you don't have access to the DB you can try creating a php file which will modify the database using magento:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once ( "app/Mage.php" );
Mage::app('default');
$db = Mage::getSingleton('core/resource')->getConnection('core_write');
$db->query("UPDATE `core_config_data` SET `value` = 'http://dev-server.com:3000/' WHERE `path` = 'web/secure/base_url';");
$db->query("UPDATE `core_config_data` SET `value` = 'http://dev-server.com:3000/' WHERE `path` = 'web/unsecure/base_url';");
?>
You need to put this file in the root magento folder or change the path to Mage.php if you put it somewhere else.
I have not tried it (becaus I don't want to kill my Shop), but I think you can just change the Port in the Magento Admin.
In System / Configuration / Web / Base URL. Just try to add the Port to the URL there. Does that work?
You cannnot rewrite a URL that Magento writes in it's HTML Output using mod_rewrite. The Request to the wrong URL (without the :8080 Port) won't even reach your server.
UPDATE:
Look at the Source of the HTML output (i.E. go to your Shop with your Webbrowser and press CTRL-U or whatever). Do tags like the following have the correct URL, including the port?
<script type="text/javascript" src="http://yourstore.com:8080/js/prototype/prototype.js"></script>
All the methods shown seem to use a very complex process to do this.
It is very simple, change the URL to include the port in Admin > System > Configuration > Web > Urls
There you can define base URL, skin and media URLs.
You are missing this:
NameVirtualHost 6x.2x.6x.1x:8080
Perhaps you just didn't copy here since your site is working?
If Magento is loading pictures from the wrong site, there's nothing you can do in your Magento's .htaccess file: picture request will never get there. They will go to whatever other web server you have running on port 80.
You can only have this problem if Magento is building absolute links that include protocol and host (a terribly pointless bandwidth waste IMHO). My advice is that you look at the application settings and see if there's a place to specify the site base URL (since the app doesn't seem to be able to find it by itself).
(I tried to access Magento's demo site but it requires registering.)
I had the same problem because i was trying to use nginx with apache togather and i changed the apache port to a different than port 80 so i can use nginx as proxy, i changed the configuration file on apache httpd.conf but seemed that my site was not working, but I cleared the dns catch of my mac, and also used another browser to open my site and it worked.