Htaccess rewrite url folder to display content from root folder

I am new to htaccess and have some problems for which I need help. On my site I have a folder (actually empty) for which I want to serve content from the root folder.

Suppose the structure is as follows:

example.com

-folder1 -index.php -anotherpage.php -.htaccess 

So, when someone goes to example.com/folder1/index.php, he will see the URL, but get the content from example.com/index.php. If he visits example.com/folder1/anotherpage.php, he will receive content from example.com/anotherpage.php. Of course, when he visits directly at example.com/index.php, he will see example.com/index.php.

I found many examples that show the opposite, but not the way I want. Also, to clarify, I want to rewrite rather than redirect, so that the URL will falsify that there are actually pages in folder1.

Any help would be appreciated.

+4
source share
1 answer

Use this .htaccess in the root folder:

 # Enable mod_rewrite RewriteEngine on # ^: Start with # folder1: name the folder # (\/?): Can containt an ending slash eg: folder1/ or folder1 # $: End with # [QSA]: Query string append, means you can use %name=value # [NC]: Non Case: Case insensitive # [L]: Last rule, stop if this rule match the url RewriteRule ^folder1(\/?)$ /index.php [QSA,NC,L] # (.*): Everything # $1: the matching filename- file must exists. RewriteRule ^folder1/(.*)(\/?)$ /$1 [QSA,NC,L] 
+3
source

All Articles