Magento test envrionment redirect to live environment - .htaccess

dear sirs,
we are running a magento shop and our hosting company made us a dev environment, we want to use to upgrade the CE Version from 1.7.02 to 1.9.1. For this purpose a database was copied and the local.xml was edited correctly to connect with the test database.
But we have a problem, that the dev-subdomain (dev.domain.com) is not working. It redirects always to the live environment index.php (domain.com).
What should we do? Our hosting provider tells us the problem is in the .htaccess file in the live folder. The test environment .htaccess is empty.
My first idea:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/ [R=301,L]
Should we delete it or change it somehow? If i change both links to dev.comain.com the URL while visitng the site is correct, but the redirection fails and we get an error message.
If i add
#Alternate default index page
DirectoryIndex dev
Then neither the live nor the test index.php do work. So what could we try instead or additionally? The Rewriterules are on.
############################################
## rewrite everything else to index.php
RewriteRule .* index.php [L]
Additionally we have this one in our .htaccess
############################################
## default index file
DirectoryIndex index.php
<IfModule mod_php5.c>
Just deleting or renaming the .htaccess does not work neither. It just still redirects to the live environment.
I will be thankful for every hint.
Best Regards
Dimitri Petrik

You need to changed base URL stored in the database. Open core_config_data table and look for following rows:
web/unsecure/base_url
web/unsecure/base_link_url
web/unsecure/base_skin_url
web/unsecure/base_media_url
web/unsecure/base_js_url
web/secure/base_url
web/secure/base_link_url
web/secure/base_skin_url
web/secure/base_media_url
web/secure/base_js_url
web/cookie/cookie_path
web/cookie/cookie_domain
You probably only have to change web/unsecure/base_url and web/secure/base_url
And forget about .htaccess redirect.

Related

Remote site not working on local server

So I'm setting up a local environment for testing and development. We use CodeIgniter as our framework.
But when I copy the whole server to the local server (I have XAMPP), and navigate to the root, all I see is a directory structure - it doesn't display anything at all that I would expect to see from the website.
I spent 4+ hours (over several days) trying every .htaccess and httpd.conf suggestion I could find on Google, stackoverflow, these forums, and more. I am able to get a 500 server error when adding garbage to the .htaccess file, so I know it's being processed. But I think my problem is possibly unrelated to the .htaccess file settings. (I don't really care if index.php shows up on the URL bar locally.)
There is no index.php on our server's root (again, our site is built with CodeIgniter). Nor anywhere else in the site's directory structure, (except /application/views/user/template/original). When I access the site live, in the URL bar it pulls up the domain name followed by: "/user/login". Looking into the /application/views/user folder shows a login_view.php, but when I try to access it directly, I get an Access Forbidden 403 error.
Per this solution, I also tried changing the DocumentRoot (in C:\xampp\apache\conf\http.conf) from "C:/xampp/htdocs" to "C:/xampp/htdocs/othersites/mysite" Same result.
How is the site loading remotely, but not locally?
Check your base_url in config.php
Here is working .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myproject
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
It turns out, for some reason, the site's root index.php wasn't in the git repo that I cloned from. I have that now, along with another (different) .htaccess file.
After changing the base_url in application\config\config.php to my localhost variant, it's working!
If I ever figure out why they didn't have index.php in that repo, I'll let you all know...

301 Redirect entire site to new directory except for index.html landing page

The wordpress site I'm working on got moved into a subdirectory therefore all the links from other sites don't work anymore. I implemented a 301 redirect with .htaccess which is great because it fixes that problem BUT the old root directory now has an index.html that has landing page my client absolutely wants to be seen.
So, how can I set up my .htaccess to redirect all traffic into the sub directory (to fix the incoming links) EXCEPT the index.html in the root directory because it has the landing page.
I don't know how htaccess works well but this is what I have right now.
Order deny,allow
ErrorDocument 404 /404.php
DirectoryIndex index.php index.html
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/$ [OR]
RewriteRule ^.*$ http://example.com/portal/$0 [R=301,L]
Thanks!!
Edit for clarification:
Right now EVERYTHING redirects from the root to the subdirectory. I want everything to redirect except for index.html in the root directory. If the user requests just the domain name (http://example.com) without specifying a page, I also want him/her to be served up the index.html page in the root directory.
The following code does what you are asking for: "if the request does not match either index.php or index.html or "/" (i.e. nothing) (and the match is not case sensitive) then serve up the alternate location"
Order deny,allow
ErrorDocument 404 /404.php
DirectoryIndex index.php index.html
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index\.(php|html) [NC]
RewriteCond %{REQUEST_URI} !^/$ {NC]
RewriteRule ^.*$ http://example.com/portal/$0 [R=301,L]
I have tested this using the excellent online testing tool http://htaccess.madewithlove.be
Using the following test cases:
http://example.com -- no rewrite, second condition not met
http://example.com/ -- ditto
http://example.com/index.html -- first condition not met
http://example.com/index.php -- first condition not met
http://example.com/some/page.html -- rewritten as http://example.com/portal/some/page.html
EDIT You said that this still didn't work quite as expected; so I brought out the big guns. By turning on "maximum logging" of everything that the rewrite engine does with the directives
RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 9
(pick any path you want, obviously), then looking at the end of the logfile in a terminal window with
tail -f /var/log/apache2/rewrite.log
You can quickly see where things are not working quite right. A bit of fiddling led me to the following code. It says "if the requested URI is just /index.html or /index.php, or if it starts with /portal, or if it is blank, then don't redirect.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index\.(php|html) [NC]
RewriteCond %{REQUEST_URI} !^/portal.*$ [NC]
RewriteCond %{REQUEST_URI} !^/$ [NC]
RewriteRule ^(.*)$ http://example.com/portal$0 [R=301,L]
The test cases worked for me - see if they work for you!
NOTE: I made these changes in the httpd.conf file, not in the .htaccess file of the root directory. You need to be careful to make it so the .htaccess file in the root directory is even read - the default Apache configuration has an Override none for that directory, so some extra work is needed. By putting this configuration change in the httpd.conf file (and issuing a sudo apachectl restart command) you avoid the difficulty. Depending on who is hosting your website, and what control you have, that may not be an option for you. There may come a point where the experts for this problem can be found on superuser.com rather than SO... but I'm hopeful this does the trick for you.

.htaccess URL Rewrite Failing - The requested URL was not found on this server

I have a very simple rewrite rule. My entire .htaccess file is as follows:
RewriteEngine On
ReWriteRule ^([a-zA-Z0-9\-]+)$ /index.php?page=$1 [L,NC]
This works perfectly on one of my development machines running Apache. It does not work however on my other development machine running Apache (mod_rewrite listed in PHP info under apache2handler). Nor does it work on the live server, which I think is running Windows.
I have tried adding the following:
RewriteBase /
I'm no mod_rewrite wizard and I'm sure it's a very simple solution but it is eluding me currently and keep receiving a 404 not found error.
One thing that is different on the two environments in which this doesn't work, is that the site is not in the root of the URL. So for example it is http://localhost/site and www.example.com/site
I have tried various syntax adjustments in the .htaccess file, and also adding the site to the base:
RewriteBase /site
Remove the 'RewriteBase /site' and try removing the / before index.php
The slash should't be there with use of .htaccess
RewriteEngine On
ReWriteRule ^([a-zA-Z0-9\-]+)$ index.php?page=$1 [L,NC]

htaccess rewrite all to index.html

I'm trying to write the .htaccess file so that whatever the user requests, he will have the page index.html
I've written this:
Options +FollowSymlinks
RewriteEngine on
RewriteRule .* index.html [NC]
I understand that this will cause: whatever the incoming request URL is, i.e, www.domain.com/*** (whatever comes after the slash), the result will be the page www.domain.com/index.html
However, I'm getting a Server error. What am I missing?
NOTE: I don't want it to be permanent redirect, I'm just trying to "hide" the content of my site for a couple of hours with that index.html page (which says that the site is under maintenance).
If you want to redirect everything to temporary maintenance page, you can do :
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/maintenance.html$
RewriteRule .* /maintenance.html [L,R=302]
the R=302 flag is used to generate a temporary redirect
Try to remove Options +FollowSymlinks , some servers won't allow you to overwrite a php.ini setting.

CakePHP and .htaccess in shared hosting environment

Greetings!
I have CakePHP based app on shared hosting I wonder if there's a way to clean up the url through .htaccess. What bugs me is that I have to have index.php in it or I get a 404:
project.com/index.php/controller/method
Initially I was getting a 404 error no matter what and my host admin ended up setting RewriteEngine off and this is what it looks like now
<IfModule mod_rewrite.c>
RewriteEngine off
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Is there fix for this without the .htaccess? As it is right now, does it pose any type of security risk?
Thanks
You need three .htaccess files :
/.htaccess
/app/.htaccess
/app/webroot/.htaccess
If the one you pasted in your question is the one at the root of your website, that's probably where your problem comes from. These directives file would rewrite URLs to project.com/webroot/, which doesn't exist. It should redirect to project.com/app/webroot/, which will in turn rewrite to index.php?url=$1 (relative to project.com/app/webroot/).
I'm not pasting the files here; the three of them are available in the CakePHP releases as well as in the Book: http://book.cakephp.org/2.0/en/installation/url-rewriting.html (check the 3rd item in the page).
Are you sure the mod_rewrite module is enabled on your shared hosting?

Resources