Why I am getting not found error on js/index.php/x.js in Magento? - .htaccess

Magento forgotpassword.phtml page uses
js/index.php/x.js?f=prototype/prototype.js,prototype/validation.js,mage/adminhtml/events.js,mage/adminhtml/form.js,scriptaculous/effects.js
and this returns custom Magento template 404 error page.
Apparently js/index.php script is supposed to concatenate provided scripts (for optimization purpose) and return virtual x.js file which physically does not exist on the server.
But in my case this does not work. For testing purpose at the beginning of js/index.php I added logging some info to a file. When I invoke js/index.php an entry is added to the script. When I invoke js/index.php/x.js nothing is logged meaning that control is never passed to js/index.php.
Browsing internet I found information that using nginx for static files can introduce the problem, but I turned nginx off in my hosting settings. Admin of my hosting claims that this works in case of everybody's else Magento installations on that server whether nginx is turned on or off.
How can I troubleshoot the problem? What should I look for? Can something in the .htacces be blamed for it? Would the fact that my Magento installation is located in subfolder contribute to this problem somehow?

Finally I found the root cause of the problem. Since I have a multi Website Magento setup I need to add extra entries to my Magento .htaccess setting environment variables based on which right website is selected to be shown in the frontend. I used a template proposed on several internet articles. It goes like this:
RewriteCond %{HTTP_HOST} ^domain1$
RewriteRule (.*) $1 [E=MAGE_RUN_CODE:domain1]
RewriteRule (.*) $1 [E=MAGE_RUN_TYPE:website]
RewriteCond %{HTTP_HOST} ^domain2$
RewriteRule (.*) $1 [E=MAGE_RUN_CODE:domain2]
RewriteRule (.*) $1 [E=MAGE_RUN_TYPE:website]
The issue went away when I used another solution (which however may be not supporter by some servers):
SetEnvIf Host ^domain1$ MAGE_RUN_CODE=domain1
SetEnvIf Host ^domain1$ MAGE_RUN_TYPE=website
SetEnvIf Host ^domain2$ MAGE_RUN_CODE=domain1
SetEnvIf Host ^domain2$ MAGE_RUN_TYPE=website

Related

How do I remove a folder from a URL?

First of all, this question has been asked a few times on stack, however, none of the answers seem to work for me.
I have a website which has a "pages" folder in the root, I want to store all of my website pages in there.
Here's my structure
/pages/folder/folder2/index.php
I want to make it so the link displays:
https://wwww.website.com/folder/folder2/index.php
Removing the "/pages/" part of the URL, when I try all of the answers suggested previously, I get a 404 error.
Here is the htaccess I'm using
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^pages(/.*|)$ $1 [L,NC]
</IfModule>
and i also tried:
RewriteEngine On
RewriteRule ^pages/(.*)$ /$1 [L,R=301]
This htaccess is in the root. I can't seem to get it working, can anyone offer any suggestions? Thank you!
Your second attempt looks fine, though it can be imporoved a bit:
RewriteEngine On
RewriteRule ^/?pages/(.*)$ /$1 [R=301]
That rule should work inside the http servers host configuration or in some dynamic configuration file (".htaccess" style file) if the http server's rewriting module is loaded. You definitely should prefer the first option, but if you really need to use a dynamic configuration file then take care that the interpretation of such files is configured at all and that the file is placed in your hosts's DOCUMENT_ROOT folder and is readable for the http server process.
If that does not work then you need to start debugging. In this case you will start by monitoring your http server's error log file while making test requests. If no hint appears in there you need to enable rewrite logging which allows you to learn what exactly is going on inside the rewriting engine. See the official dpcumentation for the apache rewriting module for that. As typcial for OpenSource software it is of excellent quality and comes with great examples.

htaccess works with www.example.com but not example.com

I have installed Ghost, which needs nodejs to run. I'm doing this on an Apache Linux server via managed hosting. They kindly let me login with SSH access so I've been able to setup nodejs and Ghost using the standard installation instructions. I installed ghost to the root of my domain so in normal operation someone would go to example.com and it'll show them my blog. Well that's what I'd hoped.
However now when I've come to load Ghost in my browser I discover because I'm accessing it the way I am, and that Ghost doesn't do server configuration, I seem to need an htaccess file to be able to make the site reachable.
So, I have created this htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ http://127.0.0.1:65515/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:65515/$1 [P,L]
</IfModule>
With that saved to the root, if I go to example.com/ghost (the admin panel for Ghost) it works. Nothing wrong there, looks great. If however I try and visit the root, ie goto example.com, instead of showing me the index, it shows me index.js - that is, it literally loads the contents of Ghost's index.js file and displays it instead of parsing it and displaying the main index of the website.
IF however I go to www.example.com then it all works. So whatever the problem is it's because I'm not using www. in the domain.
I would prefer it to work both with or without the www in the URL though. I did try adding some solutions to redirect non-www requests to www.example.com to th ehtaccess but for some reason it still doesn't work (as in if I type example.com it doesn't redirect me to www.example.com).
I think maybe you should be using mod_proxy rather than mod_rewrite. At least, that's what I've used in the past. Apache will catch requests coming in on port 80 and then redirect them to port 65515 where your node server is listening.
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass
Like this:
ProxyPass / http://localhost:65515/
I figured it out. Wasn't anything to do with htaccess, or Ghost or nodejs or anything like it. No, instead the problem was the sodding server was caching the website. I discovered the setting to delete the cache and it all started working fine, so, this is now solved.

Can't get my Zend Framework 2 project working on hosting server

Currently I am developing a webshop in PHP. For this I use the Zend Framework 2.
All of my routes exist of a locale i.e. "nl_NL" or "en_EN", followed by a controller and an action www.mydomain.com/nl_NL/profile/login. Look here for an example of a route used in my project. This one belongs to the Profile Module: http://pastebin.com/jmim47w8.
If the visitor has no account, and no Cookie is set, the locale variable will first be set to the variable retrieved from the following function:
locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE'])
If a cookie is set that value will be used.
On the other hand, if a user does have an account and is logged in, the variable used will be retrieved from the user's profile.
My entire script does work on a localhost. However, on the server it doesn't.
When loading the page nothing gets shown. I have checked the error logs and couldn't find anything. However, when i place /nl_NL/ or any other locale that meets the requirements of the "locale route" regex in the url manually, it does work.
My first thought was that the url_rewrite apache module was not installed or activated, but since other websites use this module as well, and they are on the same server this doesn't seem logical. Of course I did try to check wether it was enabled by running some scripts, but to no avail. Since our server is setup to not allow shell scripts to be ran, or to check wether apache modules are enabled using phpinfo() it's quite hard to make sure.
I have tried to verify that my .htaccess file is correct, but I'm pretty much a noob at .htaccess. This is my .htaccess:
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
To see what my IndexController looks like look here: http://pastebin.com/AEgm3Jmk.
All in all, I would really like to know how to get a Zend FW 2 project to work on a hosting server while still using url rewrite or any other way that makes it possible to use locale variables.
If there is something missing from this post that is needed to help me further, I will be happy to post it.
I have solved the problem, everything is working fine right now.
I found the problem to be in my local.php config file. The problem was
an error within this file, so it was actually a write error ( corrupt file ).
#Alex thanks for the help though, appreciate it.

.htaccess redirection on local server

One of my doamins has been indexed by Google in various ways, mail.mydomain.com, ftp.mydomain.com, pop.mydomain.com... instead of simply www.mydomain.com.
I have inserted the following two lines in my .htaccess file and this seems to be working well in telling Google to update it's index:
RewriteCond %{HTTP_HOST} !^(www)\.mydomain\.com [NC]
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]
However, when these same two lines are included on the .htaccess file of my local server (127.0.0.1) I can no longer reach 127.0.0.1 as I'm always redirected to www.mydomain.com.
does anybody know how to write these two lines such that I don't have to comment them out on my local server?
I've dealt with that problem by putting the relevant lines into the Apache configuration, and then having separate live and development configurations. They are likely required anyway for file-path reasons and servernames, if nothing else.

Using .htaccess to redirect all requests from subdomain to main domain

I have a hobby website for a number of different projects and want each project to have it's own subdomain, like foo.domain.com, bar.domain.com etc.
I use Drupal with the Domain Access module, meaning all subdomains should point to the base installation of Drupal, and then the module recognizes what subdomain the request comes from and serves a page according to that.
Now, since this is just a hobby project, I keep it on a free shared hosting account, which means a few limitations:
No wildcard subdomains.
Each subdomain is linked to a subdirectory with the same name, for example domain.com goes to /public_html/ and sub.domain.com goes to /public_html/sub/ The hosting forces this.
I can't create symlinks.
I have limited space and databases, meaning I can't just make a new installation for each project. (Hence the Domain access module)
My domain registrar (Godaddy) doesn't play nice with shared hosting. I tried hosting the DNS with them and doing a wildcard A record to my hosting server, but it didn't work, and Godaddy don't allow wildcard CNAME records for some reason...
It seems the only option left for me is some .htaccess magic.
I need a .htaccess file to put in the subdomain director(y/ies) to tell apache:
The data is in the root web directory
To not change anything else, so that the Drupal module knows what subdomain was requested and the user still sees "sub.domain.com" in the browser window.
Thankful for your help!
TL;DR
How can I tell Apache to use the data from another directory (i.e. /public_html/ instead of /public_html/subdomain/) WITHOUT making a redirect or any changes to the headers? HTTP_HOST needs to be intact.
Thanks!
Try this:
http://kb.mediatemple.net/questions/242/How+do+I+redirect+my+site+using+a+.htaccess+file%3F
try this
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com%{REQUEST_URI} [R=301,L]
try this.
RewriteEngine On
RewriteCond %{HTTP_HOST} sub\.example\.com$ [NC]
RewriteRule ^sub/(.*)$ $1 [L]
Not sure if it will work, because I don't know how your host configured to server to map the subdomains to a different folder.
Otherwise you could try the Proxy flag, but that will not set the correct http_host variable in php.
Are you sure Drupal doesn't have a different method of doing multiple installs. I know WP did have a option to use a prefix for all table-names so multiple installs can coexist, using the same database, as long as they use different prefixes. Not sure how big a Drupal install is, and what amount of diskspace your host provides.

Resources