htaccess rewrite folder url to show content from root folder
I am new to htaccess and have some problem for which I need help. In my site I have a folder(which is blank actually) for which I want to serve content from the root folder.
Lets say the structure is as below:
example.com
-folder1
-index.php
-anoth开发者_运维知识库erpage.php
-.htaccess
So, when someone go to example.com/folder1/index.php he will see the url as that but get content from example.com/index.php. If he visit example.com/folder1/anotherpage.php he will get content from example.com/anotherpage.php. Ofcourse, when he visit directly to example.com/index.php he will see example.com/index.php.
I found many example which shows the opposite but not as I want. Also to clarify, I want to rewrite, not redirect so the url will fake that there is are actually pages in folder1.
Any help will be appreciated.
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]
精彩评论