htaccess http request re-routing - apache

Reason for Problem:
I'm working on a website and wanted to work on it without making edits to the live website. My hosting package allows for "infinite" domains. So instead of editing the live website I create a new domain, without purchasing the domain name and am trying to develop with this new domain.
Issue At Hand:
This issue is that the reference file paths don't work anymore and return 404 when trying to load the webpage. My original website directory structure looks like this
cgi-bin
config
public_html
->JSfiles
->CSSfiles
->PHPfiles
The new one is the same structure however when you open the "temporary web address" the URL looks like this
http://217.199.187.199/myTempAddress.com/"
instead of
http://myTempAddress.com/
so when my index.html file looks for /JSfiles/someJSfile.js its requesting
http://217.199.187.199/JSfiles/someJSfile.js
when it needs to be requesting
http://217.199.187.199/myTempAddress.com/JSfiles/someJSfile.js
Things I've Tried Unsuccessfully:
I would really like to fix this by redirecting with the .htaccess file in the root directory on the server. Ive tried using the following directives with no success.
Redirect /217.199.187.199/JSfiles/mustache.min.js http://217.199.187.199/myTempAddress.com/JSfiles/mustache.min.js
Redirect /JSfiles http://217.199.187.199/myTempAddress.com/JSfiles/
Redirect /JSfiles http://217.199.187.199/myTempAddress.com/
Redirect /JSfiles 217.199.187.199/myTempAddress.com/
Question:
How can I redirect the requests to the right location? I need all the the requests to be of the form http://217.199.187.199/myTempAddress.com/someDir/Somefile.ex

You need to read up a bit more on Virtual Hosting in particular name based virtual hosting.
https://httpd.apache.org/docs/current/vhosts/name-based.html
It sounds like your provider might support name based VHosts but what you're trying to do is not taking advantage of that. To do what you want ie have path that points to a different version of your site is best achieved using mod_rewrite. See this
https://httpd.apache.org/docs/2.4/rewrite/remapping.html
You need to make sure that your provided actually supports this.

Related

prestashop not changing base url

I have an installation of prestashop 1.6 on a domain www.mydomain.com and a virtualhost on a server for redirecting to the prestashop/public_html folder. This is my main website working perfect.
Now i would like to clone the installation in another folder prestashop/clone_html and i created an alias on the virtualhost from www.mydomain.com/clone to prestashop/clone_html
Now if i access the clone website the frontend is not working, i get a 404 error and all the links are pointing on the main domain
I tried to change settings.inc.php change the base URI on the database and delete both .htaccess and cache but the links are never changing.
I think maybe the problem is coming from multilanguage redirect?
Do you have any idea what i should try to change?
Thanks
That is a good one! If you want to change the URL of the store and you have already migrated the contents (so no access to the admin is possible or you donĀ“t want to bother), you may do the change directly at the PS table where this information is kept. The name of the table is <prefix>shop_url. Once you access it, the content is self explanatory. You have to play with domain or domain_ssl and then with physical_uri.
Also, using a subdomain as has been suggested in a comment may be a good idea. Depending on your hosting, you may be able to define a subdomain and make it point to a subdirectory. This keeps the physical_uri to / and may avoid other potential problems.

Apache routing without htaccess

I am working with a custom website built in PHP running on Apache server. The client wants to move it to a new server. I moved everything including the .htaccess file, the homepage loads fine but all the other urls like site.com/register isn't working. I'm sure this is not handled by code in the old server because I renamed everything (including .htaccess) and it still works. If I create a file like test.php in the old server, I can access it like site.com/test. It doesn't even hit the index.php file. Also, not all the urls work like this, some are loading through files in other folders.
So my question is - what are the possible ways that Apache can let user access site.com/test without the .php extension. It must not be using .htaccess. Also, we should be able to add exceptions to this so that some urls can be loaded differently.
you can achieve same thing in hosts file if you are using Linux server. you need to define same rules in hosts configuration file.

How to point different domains to the same site

I've found myself in a situation where I have to use different domains for the same site.
It's a multilingual website that uses the path for the language so I have something like:
mysite.com/en
mysite.com/es
mysite.com/fr
mysite.com/ru
What I need is something like
mysite.com/en
misitio.es/es
monsite.fr/fr
bladimir.ru/ru
It's an Apache server. We enabled domain aliases and if I enter misitio.es the server redirects the web browser to mysite.com/es but showing misitio.es in the url.
What I would need is each domain to work on their own, not redirecting me, sharing all the content and source code. There should be no differences neither in files or in the database, and the htaccess should be configured to redirect each language (/es, /en, /fr, /ru) to its respective domain (*It's the last thing to do, we have not changed thw htaccess file yet).
I've found this guide for multisites in drupal, but it explains how to build a multisite from zero and my website is already in production, also, I'm not sure on how does it apply to my specific problem.
Is it possible to achieve what I need?
Any advice would be helpful.

How can I redirect and open content from a different directory to DocumentRoot in .htaccess?

I've tried searching for my exact issue and couldn't find it. I don't want to redirect to a different domain, I merely want to achieve the equivalent of Alias in .htaccess. I'll explain what I have.
I'm using SiteGround cloud hosting and don't have access to anything other than .htaccess files. I have the following directory structure:
/var/www/company.com
/var/www/microsite
company.com contains a Drupal installation. I could create microsite as a sub-directory there but I want to keep the content and code separate.
On an in-house setup I have access to sites-available and have simply created an alias on "/microsite-name" "/var/www/microsite" and all is great - https://www.company.com/^ opens the main Drupal site, whilst if someone opens https://www.company.com/microsite-name content is loaded from /var/www/microsite.
But with this cloud hosting, alias isn't allowed in .htaccess, so how do I achieve the same in .htaccess?
Thanks!

how do i use htaccess to make http requests work properly

I currently have css and javascript file calls (amongst other things) like the following:
href="/css/default.css"
src="/js/ui_control.js"
putting the preceding / in to make the files relative to the root.
This works great when my page is in the root of the domain.
However, I'm currently in the middle of transferring my site to a new hosting provider and as such have a temporary URL which is: HOST-IP/~username
As such, all file calls are trying to be called from HOST-IP/css/default.css etc instead of within the ~username sub-folder.
Of course I can wait until the domain name servers propagate but that's beside the point.
How would I go about writing a rule in the .htaccess file that would redirect all file calls that start with a /, from going to HOST-IP/FILE-CALL, and instead to go to HOST-IP/~USERNAME/FILE-CALL. ?
Any ideas?
I'd suggest changing the references in your HTML to the files to be relative, as this will work either in a sub folder or as the root of the domain.
This works great when my page is in the root of the domain. However, I'm currently in the middle of transferring my site to a new hosting provider and as such have a temporary URL which is: HOST-IP/~username
How would I go about writing a rule in the .htaccess file that would redirect all file calls that start with a /, from going to HOST-IP/FILE-CALL, and instead to go to HOST-IP/~USERNAME/FILE-CALL. ?
Unless you can put a .htaccess at HOST-IP/.htaccess on the new server, you can't do this with .htaccess. It sounds like you're on a shared host, so any approach that'd let you do this with .htaccess would allow you to hijack everyone else's site on the server.