Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep URL the same, load index.php

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!

like image 932
felipetnh Avatar asked Dec 04 '25 13:12

felipetnh


2 Answers

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>
like image 85
Latheesan Avatar answered Dec 07 '25 02:12

Latheesan


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.

like image 40
Paul Dixon Avatar answered Dec 07 '25 03:12

Paul Dixon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!