tags:

views:

55

answers:

3

Hi,

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

+3  A: 

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"&gt;&lt;/script&gt; 
pableu
Thank you for replaying pableu. I cannot get to the admin because the website is not coming neither frontend nor backendhow would i access System/Configuration/Web/Base Url?No the links are not including the port and that is the issue. Are you saying that when magent includes js, css files etc. it does not user rewrite rule to the base url?Thanks again for helping
latvian
No, Magento never rewrites its URLs according to the rewrite rules. It never looks at the .htaccess file. The *webserver* uses .htaccess to process *incoming* requests. The rewrite rules are never used to create URLs on the server-side. Anyways, if you don't have access to the Admin, you'll have to change the URLs in MySQL, as Silvo describes in his answer.
pableu
A: 

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.)

Álvaro G. Vicario
Magento indeed does write absolute URL for everything. It's kinda pointless, but I never looked into turning it off. Bandwidth doesn't matter much because we use mod_gzip (oder mod_deflate, I don't remember). Here's a Magento Demo Store: http://demo.magentocommerce.com/ As you can see, all the Scripts, CSS, Images are linked to by absolute URLs.
pableu
Thanks Alvaro for replayingMy site is loading but no js, css, img src= loaded. And then when i click on the link it displays 'page not found'. I have tried with and without NameVirtualHost specified and both times the same outcome. I like your advice to look at the application settings. I guess i will have to do in database since i don't have access to neither front end nor back end.Thanks again
latvian
+1  A: 

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.

silvo
Silvo thank you and it looks like a solution but i don't have DB access at this moment to check it. Once i do i will let you know how it worked
latvian
@latvian: I added a method of changing the database with a php file, maybe you will find it helpful.
silvo
thank you Silvo. It did the trick. You are the best!:)
latvian