I realize this question has been asked many times but I have been trying for a while now and cannot get any of the previously posted solutions to work for me.
I have a webapp app hosted on my site at: www.example.com/app/
At the heart of the app is an index.php file that resides in www.example.com/app/www/
What I need is for all requests on the site to be forwarded to this /www/ subdirectory.
For example, www.example.com/app/ will forward to www.example.com/app/www/
and www.example.com/app/view/ will forward to www.example.com/app/www/view/
Thank you for any help that anyone can offer on this matter. It's been driving me crazy.
Adding this to your htaccess file in your document root (the directory that "app" is in) doesn't work?
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/app/www/
RewriteRule ^app/(.*)$ /app/www/$1 [L]
Related
I have found plenty of useful answers in this forum that got me to the point I'm at, however the configuration of my .htaccess redirect is still not 100% perfect.
Set-up
I have two domains registered:
domain1.is (only domain)
domain2.me (domain + hosting)
The domain1 redirects as wildcard everything to domain2.
What I'm trying to do
I have installed yourls (url shortened) on domain2.me/yourls and want to redirect all domain1.is/randomstring to domain2.me/yourls/randomstring.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain1\.is$
RewriteRule (.*) https://domain2.me/yourls/$1 [R=301,L]
RewriteRule ^$ store [L,R=301]
The issue
So far I got that domain1.is/randomstring goes to domain2.me/randomstring, however the subdirectory in the .htacess file seems to be completely ignored, effectively rendering the whole system unusable.
I've tried adding a condition, changing the subdirectory, etc. but can't seem to find the reason why. Can anyone help please?
Thanks in advance and cheers from Berlin!
I'll share my solution in case someone else stumbles upon this conversation. The details/history are in the comments of the question.
TLDR;
Just set up a wildcard redirect to the subdirectory.
(not sure if the first redirect is useful, but still).
Important point: you don't even need to touch the .htaccess file (in my particular case yourls already had one, so I left it as it is).
Credit: thanks #CBroe for pointing me in the right direction.
I'm working on a local MAMP website. I use a micro MVC framework to use friendly urls
so I don't need to call index.php (which is inside of public_html directory) in the urls.
To achieve that, I have the following htaccess:
RewriteEngine on
RewriteCond %{REQUEST_URI} !public_html/
RewriteRule (.*) /public_html/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
Then I have the following line in /etc/hosts
127.0.0.1 mywebsite
Also, I have the following in httpd.conf
<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs/mywebsite"
ServerName mywebsite
</VirtualHost>
So if I simply call http://mywebsite from the browser, the whole thing works smoothly.
So what's the problem?
The problem appears if I try to reach the same page from another machine in my LAN.
So if I write http://192.168.1.15/mywebsite the answer is:
Not Found
The requested URL /public_html/ was not found on this server.
I get the same message if I call http://localhost/mywebsite from my own machine.
I have the feeling that is something related to .htaccess, but I've been trying a
lot of different ideas I've found in the web, and nothing works.
I'd like to fix this, because I need other people to check the website from their machines.
If you have any clue please help. Thanks a lot.
Edit: I can't solve this, so as a temporary fix I've created a free account at AppFog for my team to be able to access the page until we go to production.
After all these years, I thought that computing would be easier... it's getting harder, actually. The htaccess file is a huge mistery to me! Thanks anyway :)
By the way... as I told you, I've found a way to fix the problem. The funny thing is I have to use a different .htaccess file. I thought you could be interested, provided that it seems you like computing stuff :)
This is the .htaccess that works in my LAN debian server:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/(www/.*)$
RewriteRule ^(.*)$ index.php [QSA,L]
As you can see, it's different from the one I showed you at my first post. My conclusion? Well, even when I always try to keep things simple, life shows me one and another time that everything can be more complicated. Look at the .htaccess file. It's so funny... I've learnt to work with it by using different combinations of code.
Isn't it crazy? Yes it is. Please let's do understandable software. Thank you!
Ok, I've been trying a lot of different things and all of them fail. The only solution I've found is to install the web site in a separated LAN debian server. Everything works ok in that way, but it's not possible to make it work from my machine with MAMP.
Why not? Well, I don't know. After a lot of years in computing, I've learnt to say "I donĀ“t know", you know what I mean.
I've been working for a few days with an AppFog account for free but, you know, that thing cannot work when you put a database and the whole thing there. Obvious.
So at the end the only solution I've found has been to put everything at that local LAN debian server.
Thank you anyway :)
I installed a small FTP space for my classmates which allows them to upload school related documents to my server. After the files have been uploaded, they can be easily accessed via a subdomain i.e. ftp.mydomain.com
Everything is working fine, the files can be downloaded and everything works properly.
There are two things which still annoy me though:
If you enter ftp.mydomain.com you see Index of /my_internal_directory instead of something like Index of /
Once you enter a sub-directory and click the Parent Directory link it will redirect you to ftp.mydomain.com/my_internal_directory/ as well
Is there any way to hide my_internal_directory ?
This is the content of my .htaccess file so far:
RewriteEngine on
RewriteCond %{HTTP_HOST} ftp\.mydomain\.com
RewriteCond %{REQUEST_URI} !^/my_internal_directory/
RewriteRule ^(.*)$ /my_internal_directory/$1 [L]
Any help would be greatly appreciated.
If you are using linux server then you can remove read permission for folder my_internal_directory
If not resolve, try to add:
Options -Indexes
on top of the file.
If still doesnt resolve please post your .htaccess file... :)
EDIT
After a comment from Seth below, and heading to a helpful apache page here, I have found that VirtualHosts are the way to go for the following issue.
/edit
--ORIGINAL POST--
First, a little background on file setup. I am running a LAMP server that hosts multiple domains. I have staging and live sites on this server, under different directories under the web root.
examples
/webroot/live/site1/[public files]
/webroot/live/site2/[public files]
/webroot/stage/site1/[public files]
/webroot/stage/site2/[public files]
The domains for each of these go to the IP of the server, which points at the webroot directory. I have an .htaccess file there to load the appropriate content based on the http_host.
examples
RewriteCond %{HTTP_HOST} ^www.site1-live.com [NC]
RewriteRule ^(.*)$ /live/site1/$1 [PT,L,QSA]
RewriteCond %{HTTP_HOST} ^www.site1-stage.com [NC]
RewriteRule ^(.*)$ /stage/site1/$1 [PT,L,QSA]
These work great for hitting the home page and any of the internal pages, even with the specific pages being like site1-live.com/view/123. Each site's htaccess handles those.
My issue (sorry it took so long to get here):
When I head to any subdirectory within a site, like www.site1-live.com/rss, the content loads just fine, but the URL changes to something like the following
http://www.site1-live.com/live/site1/rss/
Essentially showing the path from the webroot to the files.
How can I avoid this? I obviously want the url to remain www.site1-live.com/rss. Do I need an htaccess file inside the rss directory to block this somehow?
Thanks in advance!
replace ^www with ^(.*)
then have the whole url in the second line www.yourdomain.com/live/...
Doug,
why do you need the QSA flag?
Anyway, what is happening to you is that mod_index (or whatever is serving you directories) is redirecting you www.site1-live.com/rss (without the ending /) to the equivalent URL with the ending /.
If you don't use mod_alias or something list that on the rewritten URLs, removing the PT should work as you expect.
Two things:
Firstly - I have version 2 of a website located in a folder named v2, and I want to redirect any traffic that is NOT a child of the v2 folder, to www.example.com/v2
The old site located in the root was created in iWeb and has a LOT of subfolders and sub-subfolders.
So:
www.example.com/v2 = New site
www.example.com/Page.html
www.example.com/category/Page.html
ww.example.com/category/subcategory/Page.html = All generic examples of what I need to redirect.
Secondly, and I don't know if this is possible, I want to hide /v2/ in the URL, so that visitors will just see www.example.com/page even though they are actually on www.example.com/v2/page
Links are hardcoded to the v2 folder, like so <a href="v2/contact.html">
Any help is MOST appreciated. I've spent hours trying to figure this out, but I'm only just learning about htaccess and regular expressions, and am totally confused.
Thanks so much!
RewriteCond %{REQUEST_URI} !^v2/
RewriteRule ^(.*)$ v2/$1 [L]
rewrite everything by including v2 before it .
RewriteRule ^(.*)$ v2/$1 [L]
www.example.com/Page.html should now be processed as /v2/Page.html
You should not include v2/ in the url being sent to the user.
it would then become v2/v2/