views:

63

answers:

2

I want to move all my web site files (even including index.php) into a subdirectory (for exp: "abc")

For example BEFORE:

public_html
 index.php
 a.file
 directory
   an.other.file
 ...

AFTER:

public_html
 abc_directory
   index.php
   a.file
   directory
     an.other.file
   ...

I want everything to work, as it was before, but i don't want to make any redirections (visible).

People should enter "http://myexmaplesite.com/directory/an.other.file/" and by .htaccess apache serve them "http://myexmaplesite.com/abc_directory/directory/an.other.file/" BUT WITHOUT EXTERNAL REDIRECTS (301,302 etc.)

How could I route all requests to a subdirectory using mod_rewrite?

A: 

Something like

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ directory/$1 [L,QSA]
Evän Vrooksövich
I tried it. (Actually i want to redirect everything into ubenzer folder.) I've written RewriteRule ^(.*)$ ubenzer/$1 and got 500 Internal Server Error.
Umut Benzer
Have you called `RewriteEngine On` and `RewriteBase /`?
Evän Vrooksövich
Yes. And i have no idea but it resumes to give 500. But, the solution on the top worked. Thanks, anyway. :)
Umut Benzer
To explain this behavior: You’re having a infinite recursion loop as `directory/…` is also matched by `^(.*)$`.
Gumbo
A: 

Try this mod_rewrite rule in your document root:

RewriteEngine on
RewriteRule !^directory/ directory%{REQUEST_URI} [L]

Or in general:

RewriteEngine on
RewriteCond $1 !^directory/
RewriteRule ^/?(.*) directory/$1 [L]

This should be even applicable in server or virtual host configurations.

Gumbo
Thank you! :) It works like a charm.
Umut Benzer