BigPino
BigPino

Reputation: 113

ZEND - How to make it works on a shared host?

I have to move a Zend website on a shared hosting which is using Pretty URL but css files doesn't load when params is added. Before moving, i want to test with server ip adress to be sure.

For exemple
-SERVER_IP/~username/en (works)
-SERVER_IP/~username/en/news (fails because it search in "en" folder)

I would like to redirect every css files from path /css/ to my real css folder which has many css files.

I want same thing for every path /images/ and /js/ and maybe others.

Can someone help me ?

thank you!


UPDATE 1

Does path relative change between domain.com and SERVER_IP/~username? When i set /css/style.css, it search for SERVER_IP/css/style.css instead of SERVER_IP/~username/css/style.css. If i can make it works for both, my problems will be gone. But I can't test with domain because i don't have any for the moment


UPDATE 2

I've modified my hosts file in C:\windows\system32\drivers\etc\ to simulate with a real domain. As i expect, relative path aren't working the same ways.

- SERVER_IP/~username/index.php <img src="/img/world.jpg" /> => SERVER_IP/img/world.jpg (BAD, note i've lose ~username)
- www.domain.com/index.php <img src="/img/world.jpg" /> => www.domain.com/img/world.jpg (perfect)

With that change, all my path are good now and no need to redirect anything. But another problem appears. Since i use www.domain.com, index.php is shown in the URL and I don't want this : www.domain.com/index.php/en


UPDATE 3

I've found this rule : RewriteRule ^index.php(.*)$ http://%{HTTP_HOST}/$1 [R=301,NC,L] . index.php is now remove but when i'm on www.domain.com/en, it looks like en is not in the request uri and all my links move to www.domain.com/en/en/...

I paste here my .htaccess content :

Options +FollowSymLinks
Options -Indexes
RewriteEngine on
RewriteBase /

DirectoryIndex index.php index.html

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^index.php(.*)$ http://%{HTTP_HOST}/$1 [R=301,NC,L]



UPDATE 4

I got it ! I describe my entire solution below!



Upvotes: 0

Views: 154

Answers (1)

BigPino
BigPino

Reputation: 113

COMPLETE FINAL SOLUTION

I've found a solution, everything is working #1 now on a shared hosting. Here is my complete solution, I hope it will save a lot of time to somebody.

1- Complete Zend Architecture (D=Directory, F=File)

- public_html/ 
      (D) application/
      (D) data/
      (D) library/
      (D) docs/
      (D) nbproject/
      (D) public/
           (F) index.php
               ...
      (F) .htaccess

2- Remove the basic .htaccess file in "public/" folder and place this one in the root folder "public_html/" (or ../public)

RewriteEngine On

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^public/.*$ /public/index.php [NC,L]

END !!! It's all you have to do, nothing more, no tricky or dirty code! This .htaccess file solve the DOCUMENT_ROOT config problem in httpd.conf file for shared hosting.

IMPORTANT NOTE
If your domain is not forwarded at that moment (OR you want to test before moving host from a server to another (my case)) and you want to access to your website with that kind of URL
http://SERVER_IP/~username/, it will not works. The best solution is to temporaly edit your hosts file in C:\windows\system32\drivers\etc\ to add a line like this :
SERVER_IP domain.com It works great!

Upvotes: 2

Related Questions