Question

My question might be dumb, but I googled it and didn't find an answer...

Let's say I want to access my website in this given url: www.mywebsite.com/something/something_else/?some_query_string=true (I put the query string because it is going to be there, and I don't know if it makes any difference in the htaccess file)

I want it to keep the URL the same, but load the index file for no matter what URL, which is not in the root of the server. My server has an "application" folder, where all the code is.

How can I do this?

Thanks!

Was it helpful?

Solution 3

This turned out to answer my own question:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ application/index.php?url=$1 [QSA,L]

If the URL doesn't exist, it loads the index.php file inside of the folder "application", and it keeps the URL the same, which was exactly what I needed...

Thanks for the answers!

OTHER TIPS

use htaccess to re-write all request to index.php (except for when a file/dir/link is requested and it exists):

<IfModule mod_rewrite.c>

    Options +FollowSymLinks
    RewriteEngine on

    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l

    RewriteRule .* index.php [L]

</IfModule>

If you want to use Rewrite to have your requests handled by a file outside the DocumentRoot, then you can combine with an Alias directive.

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule .* application/index.php [PT]


Alias application /path/to/application

Note the [PT] on the RewriteRule which means 'pass through' - it ensures the rewritten url is passed through to other apache modules which might be interesting in processing it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top