0

So, I wanted to organise my projects for better developing. I chose using this way to organise folders & files:

www
    projects
        project1
           web
           design_tests
        project2
           web
           design_tests
...

The website of each project will go inside its "web" folder. I also wanted to access the web on the browser without putting the "web" folder name, so:

http://localhost/projects/project1
will access the physical files of:
/www/projects/project1/web

I accomplished that adding the next line to my /etc/apache2/sites-available/default file:

AliasMatch ^/projects/([^/]*)(/.*)? /www/projects/$1/web$2

Works perfectly. The problem is, in some websites, i have an .htaccess file with some RewriteRule rules. An example:

RewriteEngine On
RewriteRule styles\.css styles_20120107.css

They used to work without the alias and acessing normal. Now they don't. It redirects to the URL /project1/web/styles_20120107.css, and of course, the browser can't get it because of the Alias. I don't really know how to solve it. Can you give me some help about it please? If possible, doing modifications in the file /etc/apache2/sites-available/default, not on the .htaccess, because i want the websites to be cross-server.

Thanks in advance :)

elxordi
  • 476
  • 3
  • 11
  • Add `[PT]` flag for such rewrite rule: http://httpd.apache.org/docs/current/rewrite/flags.html#flag_pt – LazyOne Apr 12 '12 at 21:57
  • Already tried it, no result. If it should work this way, why it isn't? – elxordi Apr 12 '12 at 22:25
  • The link I gave you has explanation. – LazyOne Apr 12 '12 at 22:48
  • So, i should rewrite to -? How? I'm sorry, my english is not the best :/ – elxordi Apr 12 '12 at 23:03
  • This is the idea: `RewriteRule styles\.css styles_20120107.css [PT]` (assuming your rule is correctly working). I do not have (and never had) this kind of rewrite rule where incoming and outgoing file are in the same location. I have always had similar to what you see in that link, where new rewritten url has alias in it and it works just fine with `PT` flag. BTW -- instead of doing that alias thing -- better use rewrite rule to achieve the same -- in this case you should avoid this issue altogether – LazyOne Apr 13 '12 at 00:19
  • BTW #2 -- why not utilize **virtual hosts** feature of Apache?? This will make life so much easier and more similar-looking/behaving environment compared to deployment one. Why use `http://localhost/projects/project1/` if you can `http://project1.dev/` instead (domain name can easily be setup via `hosts` file. – LazyOne Apr 13 '12 at 00:22
  • About the BTW #1 (sorry, I can't say it without laughing lol): I told you I had already put the flag. And the example is not real, i modified it for putting it in here. But any real file I link, fails. The rule is correctly working, take that for sure. And the real one also points another inside folder, but i changed it with a file in the same location to see if it correctly worked. The general rewrite it's not a bad idea, i'll try it and i'll tell you. – elxordi Apr 13 '12 at 02:05
  • About the BTW #2: The reason is because in one server, i use no-ip. And i still want to access all the projects. So, i can't do it. Also, i'm fine with relative urls. This way I test them to work in all locations. – elxordi Apr 13 '12 at 02:06
  • You're my leader. The replacing the alias with a Rewrite worked. Please, put it as an answer, and I'll accept it as answered. Thanks :D – elxordi Apr 13 '12 at 02:18

1 Answers1

1

If adding [PT] flag does not work for you ... why not replace alias thing with rewrite rule to achieve the same -- in this case you should avoid this issue altogether.

LazyOne
  • 158,824
  • 45
  • 388
  • 391