migrating htaccess from localhost WAMP to godaddy subdomain - php

First off this is similar to other stack questions however none of the solutions helped me. so before your mark as duplicate, or whine about the question try look for solutions and not problems with the question.
Hi all, here's the scoop, I have tried to be thorough.
I have a site that is in mid development.
A potential employer wants to check out the site in its current state.
In order to do this I had to put it as a sub domain of a site I already have hosted with GoDaddy.
the site uses pretty urls that link to php scripts in various directories.
mysite.com/location
would, via htaccess rules go to a script at
mysite.com/src/script/php/location/location.php
or another example might be
****mysite.com/location/fj83jfd83****
would, via htaccess rules go to a script at
mysite.com/src/script/php/location/location.php?item=fj83jfd83
my htaccess file works on my local WAMP stack but not once on the remote goddady server hosted with linux cpanel
my htaccess file is as follows
RewriteEngine On
RewriteBase /
AddDefaultCharset utf-8
RewriteRule ^location/([A-Za-z0-9]+)/?$ src/script/php/location/location.php?item=$1 [NC,L]
RewriteRule ^location$ src/script/php/location/location.php [NC,L]
Question one
I am wondering what changes do I need to make to the htaccess file for this to work on the GoDaddy server on a subdomain like mysite.hostedsite.com?
Question 2
would the htaccess go in the base public root folder or the subdomain root folder?
Couple things to note.
I am open to options that don't use htaccess or another work around that hasn't occurred to me.
This is only for someone to view the site, so a short term patch(hack) solution is fine, the site is not ready for launch.
thanks you in advance

All I needed to do was add the subdomain to the start of the rewrite rule.
so
RewriteRule ^location$ src/script/php/location/location.php [NC,L]
needed to be
RewriteRule ^mysite/location$ src/script/php/location/location.php [NC,L]
just left it encase it helps any one in the future!

Related

How to make Magento run in my subdomain

I'm trying to build a Magento (1.9.3.1) staging site in a subdomain but can't get it to work properly. The site is working but no images, js or css files are being loaded. I've searched around but all the answers I've found don't work for me.
My main website structure is www.domain.com which has it's own website (not Magento) but then I have subdomain.domain.com with Magento installed.
Following another answer I tried editing .htaccess and added the following:
RewriteCond %{HTTP_HOST} ^subdomain\.domain.com$
RewriteRule ^/(.*) http://subdomain.domain.com/index.php [L]
but that didn't work. I tried different variations of that too.
Any ideas what I'm doing wrong? I have a dedicated server and the domain structure is:
/httpdocs
/subdomain.domain.com
where the main website root is in httpdocs. Could that be the issue?
The subdomain is set correctly in the core_config_data table as well.
Most packages like magento require root access.. this may be the issue.
Also, try to check the path to youre images.
Okay #Olcan set me in the right direction so thanks. It wasn't actually root access needed but directory permissions were not set correctly.
All the directory permissions were set to 750. Changed them to 755 and everything works. Didn't need to do anything with .htaccess either so I left it at the default
RewriteRule .* index.php [L]
and it works.

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]

htaccess redirect to subfolders resources

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!

Deployed Yii app don't build url properly to domain subfolder

EDIT (a solution):
In the end, the problem wasn't with yii configuration or with the virtual server, but with the main server. I contacted the server administrator and the issue was solved by changing the URL to which the main server (where mi virtual server is hosted into) redirects the requests, to append the string containing the virtual folder's name.
I'm not sure if this was the best solution, but it's a solution. So if you face a similar problem, you might want to contact your server administrator.
Here's the detail of the original problem and some of the options I tried, just for reference:
I've been developing a Yii application for a couple of weeks, and it works perfectly on my local server, but I'm having some troubles to make the URLs work properly when deploying the app.
In the server, I have an structure similar to this:
/www/MyApp/(index.php, protected folder, etc)
/www/yii (the framework is located here)
And I can access my website using an URL like this:
www.somedomain.ac/VirtualFolder/MyApp
My problem is that all the links generated by yii are pointed to (for example):
www.somedomain.ac/MyApp/index.php?r=controller/index
instead of
www.somedomain.ac/VirtualFolder/MyApp/index.php?r=controller/index
I tried modifying the urlManager section at the configuration, and for some reason adding these rules:
'../../VirtualFolder/MyApp/index.php/'.'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'../../VirtualFolder/MyApp/index.php/'.'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
make some of the builded URLs point to the proper action, with the complete URL, but still, other ones won't work (all the ones that send a form to the server).
I've been trying other solutions to similar problems during a couple of days (like changing the app's basepath, adding "VirtualFolder" to it) but they don't seem to work.
Suggestions on how to solve the problem will be very appreciated.
Thanks.
============================================
EDIT: I am trying to do it with an .htaccess file like this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} somedomain.ac$ [NC]
RewriteCond %{HTTP_HOST} !VirtualFolder
RewriteRule ^(.*)$ http://somedomain.ac/VirtualFolder/$1 [R=301,L]
And I copied it to my web root, but not working yet. Also tried copying it to MyApp/protected folder and directly into MyApp. Am I missing something?
Thanks.
You should try to add RewriteBase directive to .htaccess file
(how the problem was solved): In the end, the problem wasn't with yii configuration or with the virtual server, but with the main server. I contacted the server administrator and the issue was solved by changing the URL to which the main server (where my virtual server is hosted into) redirects the requests, to include the string containing the virtual folder's name.
So if you face a similar problem, you might want to contact your server administrator.

Is it possible to (virtually) move a site from www.example.org/ to www.example.org/new/ with htaccess?

I'm wondering if it is possible to upload a site to the root directory, but not make it already visible for public (and Google for SEO reasons). And what is the best way for that?
Is it possible with some rules in the .htaccess file to let it look like the site is www.example.org/new/ instead of www.example.org?
Thanks
To redirect all links to www.example.org to goto www.example.org/new add this to your .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/new/
RewriteRule ^(.*) $1 [L]
RewriteRule ^(.*)$ /new/$1 [L,R=301]
</IfModule>
I'm a bit confused by your question. You subject line seems to ask a different question to the body of the question. But if you don't want search engines to crawl your new site while you working on it add it to robots.txt (though if there is no link on your old site to the new one it should not crawl the new site anyway). And you might want to password protect it as well.
Also for SEO purposes you will not want to break links on the old site once you go live with new site. Use rewrite rules like so:
RewriteRule ^corporateplan$ /corporate-services/corporate-plan [L,R=301]
I would create a virtualhost under example.org like beta.example.org and password-protect it until the new site will launch. If everything looks fine, i would update my Apache.conf to point the new dir as DocumentRoot.
I prefer to test stuff with the definitive directory structure. That way I'm sure that nothing will break when I go live due to errors in relative or absolute paths.
If it's a brand new site, I just password protect it with Apache mod_auth_* modules. If it's a new version of an existing site, I create a new site under a subdomain.
Update
In a shared hosting environment your options are pretty limited. You have to physically upload the site in the new folder or otherwise it'll overwrite the old site. In such case, nothing special would be needed.
You may disallow robots with robots.txt. I don't know will it help you but I am using that way.

Categories