htaccess redirect to subfolders resources - php

I have a problem:
I have to modify an application written in Zend 1 that was deployed to the domain root. now to test it the customer gave me a root subfolder called [domain]/social
When I run it, I have a lot of problem because all paths are like "/resource", but in this case the fiddler show me that the request look for [domain]/resource ad not for [domain]/social/resource.
It happens with script sources, ajax urls, hrefs...all!
Is there a way to fix the problem?

I am not quite familiar with Zend, but is there a main config file that sets the application root folder? (Like joomla) You can modify that if it exists.
Other option would be to preg_match or str_replace all instances of the domain name in the code ( like when moving a Worpress site) but you should definately do that with a sample content not couple hundred pages).
And here is a htaccess snippet as well:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/social/$1 [R=301,L]
Be sure to put the htaccess under the development folder not under the root, oterwise you're facing issues.
I suggest cheking for a config file first. Hope one of this helps!

Related

How to correctly setup Apache redirects for images

I've set up a reverse proxy from my Windows server to a blog hosted elsewhere. All is fine except for the sitemaps.
The blog is on a subdomain: http://blog.example.com
The proxied domain is https://example.com/blog
As I'm using Wordpress, I've opted for Yoast SEO, but despite ARR doing the rerouting Google tools still complains about images it cannot access - on the origin domain. This is correct in one sense because I've added a second robots.txt on the subdomain, to stop duplicate content, but it doesn't make sense, in the sense that Application Request Routing should be hiding the subdomain. However, we all know that Google does what it wants to do.
I've found some code which I've added to my htaccess file:
# WordPress SEO - XML Sitemap Rewrite Fix - for reverse proxy
RewriteEngine On
RewriteBase /
RewriteRule ^sitemap_index.xml$ https://example.com/blog/index.php?sitemap=1 [L]
RewriteRule ^([^/]+?)-sitemap([0-9]+)?.xml$ https://example.com/blog/index.php?sitemap=$1&sitemap_n=$2 [L]
# END WordPress SEO - XML Sitemap Rewrite Fix
I'm not sure whether it's doing anything at the moment because the image issue still exists, so my next step would be to try and redirect images to the new domain structure... and herein lies the problem - I know absolutely nothing about Apache stuff and definitely not apache rewriting.
What I need to do is redirect anything in the uploads folder, to a new absolute path
From, /wp-content/uploads/myimage.jpg to https://example.com/wp-content/uploads/myimage.jpg
Can anyone help with this final piece of the jigsaw?
Thanks in advance.
You can probably use something like the following in your .htaccess:
RewriteCond %{REQUEST_URI} ^/wp-content/uploads/
RewriteRule ^(.*)\.(jpe?g|gif|png|bmp)$ https://example.com/wp-content/uploads/$1\.$2 [NC,L,R=302]

How do I run a CakePHP app in a sub-folder from the root domain?

I'm trying to setup a CakePHP app in a sub-folder but run it from the root domain, eg, user requests domain.co.uk and they get the webroot at {DOCUMENT_ROOT}/version-13/app/webroot.
The hosting setup doesn't allow me to change the document root so I have the following .htaccess in the root:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ version-13/app/webroot/ [L]
RewriteRule (.*) version-13/app/webroot/$1 [L]
</IfModule>
This appears to do the job. However, Cake detects the sub-folder and adds it to all the URLs it creates (eg, $this->Form->create() actions, etc) so I end up with forms posted to domain.co.uk/version-13/signup instead of domain.co.uk/signup.
I know this is probably going to be something simple but I'm hitting a brick wall. No matter what I try I can't get it to work!
It's hard to understand your setup, you should explain it more. But if I got it right, check /app/Config/core.php:
Configure::write('App.fullBaseUrl', 'http://example.com');
Change your RewriteBase / to RewriteBase /version-13/ (in your .htaccess)and you should be set right up.
I had the exact same issue when I didn't have my local server set up correctly, which forced me to put my applications in a folder of my main domain.
Please note that you can have multiple apps at one core. This could be useful for you "versioning".
Ps. after a quick Google search I found the following. Didn't read it that well, but it looks like it does the same. http://cookingwithcakephp.blogspot.nl/2008/04/installing-cakephp-into-subdirectory.html

Redirect directory to subdomain cpanel

Alright I have already contacted BlueHost Support and they couldn't figure out how to fix this issue. I've also tried to use cpanels 301 permanent redirect but that doesn't work so I decided to give it a whirl on here.
I host with BlueHost.com if you haven't caught that by now. The file structure is as follows:
public_html/
directory1/subdomaindirectory
directory2
directory3
I have my main website in my root (public_html). Then I have to create new directories and assign the url to that directory. So essentially if you typed in www.maindomain.com/directory1 it would show the website in the directory. I would like to modify the .htaccess to redirect that to it's original domain so www.maindomain.com/directory1 would go to www.directory1.com
The same for subdomains. I created subdomain.directory1.com and pointed it to public_html/directory1/subdomaindirectory and if you go to www.directory1.com/subdomain it pulls up the site.
I realize theoretically it's the same thing but it bugs me that you are able to pull up a website like that.
Is there anyway to modify the .htaccess to fix this issue?
In.htaccess you could do it like this
RewriteEngine On
RewriteBase /gorbox
RewriteCond %{HTTP_HOST} ^www.gorbox.com$ [NC]
RewriteRule ^support$ http://support.gorbox.com [L,R=301]
Put this in the .htaccess file that resides within the root folder of www.gorbox.com

.htaccess method of setting a default URL to resolve to?

We have two sites, and we've just now made an in-house development server that we want to have both sites on. What I want to accomplish is to have an .htaccess in each of the site folders that prepends the development URL of the site. For example, where they simply have a header(location: /folder/whatever.php), the files should actually go to thesite/folder/whatever.php.
Currently what happens is (for example) they'll go to 192.168.x.x/folder/whatever.php
If I understood correctly and what you want is to redirect 192.168.x.x/folder/whatever.php to thesite/folder/whatever.php, you could use this:
RewriteCond %{HTTP_HOST} !^thesite.com$
RewriteRule ^(.*)$ http://thesite.com/$1 [R=301,L]

how do i hide /magento/ in my site's url?

A site has an existing system (lets call it mysite)
and the client asks to put in magento.
My directory structure goes something like this:
ROOT
-index.php (this is the app's main controller)
-.htaccess
/blog (runs wordpress)
/assets (current system's media folder)
/magento (this is where all magento files go)
Problem is if I set up magento and specify in the installation that base URL is http://example.com, magento loads up mysite.
Leaves me no choice but to setup magento with base URL set to http://example.com/magento/ and it runs perfectly.
However the client wants me to feel hell and asks me to hide magento in the URL.
I’m not really versed in .htaccess and I know only simple rewrite codes so I tried forwarding any HTTP requests that start with /magento to the magento folder and came up with:
RewriteCond %{REQUEST_URI} !^/magento(.*)
RewriteRule (.*) /magento/$1 [L]
Just when I thought it was working, mysite links all became unaccessible and forwards to the magento system displaying it's 404 page.
So, uhm, can I ask for help how to construct the .htaccess to hide the /magento/ on the URLs without affecting the current system aka mysite?
Because you have existing applications off the webroot, you cannot get away with using nothing instead:
### webroot/.htaccess
RewriteRule ^whatiwanttouseinsteadofmagento/(.*)$ magento/$1 [L]
From how I see the problem you will not be able to hide magento completely and use your site as well in the same time.
If you want Magento in the root of the public folder you should just point the virtualHost to your magento installation but this will let your blog and your main controller out of the public view. This is more or less the same with what you did by redirecting all calls in the .htaccess to magento folder.
What I suggest is to change the magento name to something more anonymous like "shopping" or "cart", and remember that a folder rename is preferable to a .htaccess file in terms of security and performance.
Let's look at it:
RewriteCond %{REQUEST_URI} !^/magento(.*)
So we're saying the condition is anything that is not /magento(.*), so everything but that directory? This would redirect everything, including your blog, assets, and any other directories.
Without specifying each and every file that needs to be redirected to the magento directory, there really is no easy way of doing it. I suppose you could redirect any file that does not contain a "/" in it and ends with the extension .php to the magento directory. That way only files in the root web directory will redirect to magento, but if you used other directories inside the magento directory you'd still need to add separate rules for them.
this answer comes very late but I guess you wanted something like
RewriteCond %{REQUEST_URI} !^/(blog|assets|magento)(.*)$
RewriteRule ^(.*)$ /magento$1 [L]

Categories