Help needed: rewrite an url in base of the http_request

New to mod_rewrite? This is a good place to start.

Help needed: rewrite an url in base of the http_request

Postby Nokao » Mon Apr 13, 2009 11:35 am

Hi all.

I need to rewrite an incoming link like:
www.mysite.net/files/
In a /home/mysite.net/ or a /home/CMS/mysite.net/ folder.

Is it possible?

I need to do this for every incoming http_request because I have 30 websites linked to the same folder because I use a CMS that uses a different database (but the same php files) for every http_request.
Nokao
 
Posts: 8
Joined: Mon Apr 13, 2009 11:25 am

Postby richardk » Mon Apr 13, 2009 1:43 pm

I need to rewrite an incoming link like:
www.mysite.net/files/
In a /home/mysite.net/ or a /home/CMS/mysite.net/ folder.

I don't understand.

What are the incoming URLs?
What is supposed to happen to them?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Nokao » Mon Apr 13, 2009 1:54 pm

The incoming links are not supposed to change... and are like:

http://www.site1.com/files/image1.jpeg
http://www.site2.com/files/image2.jpeg

For this two examples, I would like the files to be in this paths:

/home/CMS/files/site1.com/image1.jpeg
/home/CMS/files/site2.com/image2.jpeg

So that a user that browse:
/home/CMS/files/site2.com/image1.jpeg
don't find the image.

Actually I did a similar thing with a symlink that from /home/CMS/files points the /home/ directory, but that is so dangerous.
Nokao
 
Posts: 8
Joined: Mon Apr 13, 2009 11:25 am

Postby Nokao » Mon Apr 13, 2009 10:21 pm

I polished a bit the explanation.

Isn't that an easy question?
I thought that the Rewrite_Cond was the solution... but I don't understand the guide it's too much for me.
Nokao
 
Posts: 8
Joined: Mon Apr 13, 2009 11:25 am

Postby richardk » Tue Apr 14, 2009 7:26 am

What currently happens?
What is site1.com's document root?
What is site2.com's document root?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Nokao » Wed Apr 15, 2009 2:23 pm

They point both on the same root: /home/CMS

Only the database changes, the CMS looks the HTTP_REQUEST and answers with a different content using a different database.
Nokao
 
Posts: 8
Joined: Mon Apr 13, 2009 11:25 am

Postby richardk » Thu Apr 16, 2009 8:43 am

Try the following in a .htaccess file in /home/CMS
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(.+)$
RewriteRule ^files(/(.*))?$ /files/%1/$2 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Nokao » Thu Apr 16, 2009 9:07 am

The CMS (WordPress) uses already an .htaccess file.

How do I put the two files toghether? can you help me?

That's the other:

Code: Select all
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
Nokao
 
Posts: 8
Joined: Mon Apr 13, 2009 11:25 am

Postby richardk » Thu Apr 16, 2009 1:51 pm

Try
Code: Select all
Options +FollowSymLinks

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{ENV:REDIRECT_STATUS} ^$
  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC,OR]
  RewriteCond %{HTTP_HOST} ^(.+)$
  RewriteRule ^files(/(.*))?$ /files/%1/$2 [QSA,L]

  # BEGIN WordPress
  RewriteCond %{ENV:REDIRECT_STATUS} ^$
  RewriteCond %{SCRIPT_FILENAME} !-f
  RewriteCond %{SCRIPT_FILENAME} !-d
  RewriteRule . /index.php [L]
  # END WordPress
</IfModule>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Nokao » Fri Apr 17, 2009 2:17 am

Wow it seems to work.

How will php take this?
It's just and url rewriting for browsers or the files will be usable also by php?
Nokao
 
Posts: 8
Joined: Mon Apr 13, 2009 11:25 am

Next

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 1 guest

cron