How to access one website from different directories in Kohana - kohana

I have big issue of how to do this.
I have a virtual host and access my project via it. I know want to redirect it to more friendly and accessible form.
What I use:
http://localhost/api/users
What I want:
http://api.mywebsite.com/users
I cannot determine if I should somehow change routes in boostrap.php or make some changes in .htaccess file (tried Redirect and RewriteRule but failed miserably). I would really welcome any kind of help on this topic.
(I am semi-begginer in programming, thanks for understanding that)

You can copy the /system/config/url.php to /application/config/url.php
pu

Related

Ignore last part of URL with .htaccess

We have a FAQ page /faq (tab style) where every question should have its own 'ghost' url/page. So users could visit eg.
/faq/question-1
/faq/question-2
/faq/question-3
The problem is question-1, question-2, question-3 are not actual pages but just sections on /faq. For SEO, aesthetics and usability reasons we do not want to work with ?q= or #
I've searched and tried every .htaccess thread I came across but without result.
Is there a way we can show the page/faq when visiting /faq/question-1 and keep the url /faq/question-1 with mod_rewrite? (we cannot hardcode it because we do not know all future question slugs) So basically something that tells the browser: if the first url part is /faq/, just ignore everything that comes behind but keep the url.
Thanks
This is a trivial rewriting task and it is unclear why this should not work for you:
RewriteEngine on
RewriteRule ^/?faq/.+ /faq [END]
Since you claim that you "tried every .htaccess thread you came across" and this clearly works the question is: why not in your setup? But since you did not tell us anything about your setup we cannot really offer more help...
These are some general hints though which you should go through:
Where did you implement the rules you tried? In the http server's host configuration or in a distributed configuration file?
If you are using a distributed configuration file (".htaccess") then how did you make sure such files are interpreted by your http server and how did you test that?
Did you check your http server's error log file for hints?
Did you make sure that you are not actually looking at cached responses? So did you really test with a fresh anonymous browser window using a "deep reload"?
Since the CMS you are using requires own rewriting rules, where did you add those rules you tried? Remember: the order is important!

css not working properly after forbidding a folder

Good day. Got a problem here. I'm trying to forbid a folder and i succeeded from it,the problem for now is, I can't use it anymore.My web design does not work when I included it. How can i fix this?
I have tried to use options -indexes but it would not block the access if someone knows the file name like folder/css/index.css.
How can I block a user from accesing it without affecting my web-design.
By blocking access to the folder, you stopped the browser from being able to access it, which it needs to do in order to display it.
You won't ever be able to totally stop users from directly accessing the css file, if they're determined enough. The browser has to download the css file (so too can the users).
There are steps you can take to make it harder though. You could obfuscate/minify the CSS code to make it harder for people to understand - http://www.cssobfuscator.com
You could also check to make sure the referrer header is your website to prevent hotlinking - see http://www.htaccesstools.com/hotlink-protection/
Ultimately though, it will always be accessible and visible to your users
You can forbid access to the folder using the following in your /.htaccess
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !your_ip_address_here
RewriteRule ^folder/css/index\.css - [F,L,NC]
That means only your IP address will be able to access the protected folder.

Symfony2/ get variable from subdomaine and htaccess

I using Symfony2.
What would be the best practice to get a variable from URL. I am using subdomain to get the city.
Ex: paris.website.com
how do I get Paris as variable.
I believe I need to play with Kernel and htaccess, but I haven't figured out how.
Thanks if you can put me on right tracks about that.
Cheers,
Pierre.
You should read the documentation of Symfony. One of the basis components of Symfony is the Routing that provides exactly what you need :
www.mysite.com/paris/
Using the subdomain is not the solution, but you can play with .htaccess to rewrite subdomain paris.mysite.com to www.mysite.com/paris (if web server allows it) after having configured your route in Symfony.

.htaccess and sessions for security?

In my application users have their own "websites" which can be reached if they are signed in.
However, since these websites are just directories containing html and other documents everyone in the world can reach them if they know the address. I can't have that :) A user should be able to decide whether or not thw world might see their files or not.
Can I use .htaccess to activate a PHP-script every time a request is made to that directory?
I.e. if reqested-site is "/websites/{identifier}", run is-user-allowed-to-view.php?website={identifier}
The identifier is a numeric value which refers to both a physical folder and a post in the database... and the script would then return true or false.
Or is there perhaps another way of solving the same issue?
Cheers!
You can use mod_rewrite to rewrite requests with such a URL internally to your script:
RewriteEngine on
RewriteRule ^website/([0-9]+)$ is-user-allowed-to-view.php?website=$1
But this rule is only for the URL path /website/12345 and nothing else.
Or have every page as a PHP page and just put at the top a single line to redirect if the session / cookie is incorrect or not set. Obviously wouldn't work for non-PHP content such as images.
What you need is a proper front-end (written in whatever language). You need to have your web-server (Apache in your case it seems) pass the requests to the said front-end.
You cannot do what you are asking for with just .htaccess files.

re-direct / re-write my domain

First, I have already spent the past few hours trying to find a solution for this, but have had nothing but non-working solutions :(
It's pretty simple - I'm pointing the DNS of a new domain to my current hosting, but when I visit the new domain, I'm just viewing my original site (the one i got with my hosting).
Let's say my original site is "www.originalsite.com" - the content for my new domain is at "www.originalsite.com/newsite.com/" (dots included).
Now I just need to get "www.newsite.com" to re-direct to it's own directory AND re-write itself to hide the directory name.
So yeah, "www.newsite.com" needs to use the content in "www.originalsite.com/newsite.com/", but remain displayed as "www.newsite.com" in the URL bar.
Cheers for any input - really appreciated :)
PS: I'm using ColdFusion and previously made a useful re-direction, but the result was typically "www.netsite.com/newsite.com/" - which is not what I want :)
Oh...and yeah, I'm hoping for an .htaccess fix :) thanks!
If you have full control over the server, a VirtualHost in httpd.conf is probably a better solution. For example:
<VirtualHost newdomain.com:80>
ServerName newdomain.com
ServerAlias www.newdomain.com
DocumentRoot /path/to/webroot/newsite.com
</VirtualHost>
If you don't have the ability to do this directly, any good host will provide a "Park Domain" function which allows you to achieve the same effect - specifying your new domain and identifying which directory you want it to point to - via the web control panel.
However, if you don't have the ability to do that, here's a mod_rewrite for .htaccess that should work:
RewriteEngine On
RewriteCond %{REMOTE_HOST} (www\.)?newdomain\.com
RewriteRule ^(.*)$ /newdomain.com/$1 [L]
CrystalTech have just recentely installed a mod that provides htaccess ...
Though they've only done it one server so far :) so I'm being moved onto that server.
Problem solved I guess - heh!
PS thanks for the help anyway guys :)
You could do the redirect with a "cloaked" frame page.
That way the URL in the browser's address bar stays the same (no extra path), and it remains simple to use the subdirectory.
The following link describes this for classic ASP - but it should be simple to convert to any server side scripting language/platform:
http://www.simpledns.com/kb.aspx?kbid=1151

Resources