6

I've been looking on various sites reading mod_rewrite examples for a few hours, and have used it many times before successfully... but I'm trying something new with it now and can't for the life of me get it working!

I'm using a PHP file manager tool called AjaXplorer, I have it in a subdirectory on the root of my server /ajaxplorer-core-4.0.4. When I go to the root of my site http://domain.com/ I want it to invisibly redirect to the /ajaxplorer-core-4.0.4 folder (but still show the root domain in the address bar).

I still want to be able to access the other files/directories on the root as normal just typing in the path.

I assume this is possible? Seems relatively simple but I just can't get it working.

AjaXplorer seems to load js files and images etc from /ajaxplorer-core-4.0.4/plugins, I have a feeling that's where it's tripping me up.

Any pointers would be massively appreciated! Thanks

Michal
  • 15,429
  • 10
  • 73
  • 104
BT643
  • 3,495
  • 5
  • 34
  • 55

2 Answers2

11

Found it on another answer luckily :)

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^(www.)?site.com$ 
RewriteCond %{REQUEST_URI} !^/subdir/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /subdir/$1 
RewriteCond %{HTTP_HOST} ^(www.)?site.com$ 
RewriteRule ^(/)?$ subdir/index.php [L]
BT643
  • 3,495
  • 5
  • 34
  • 55
  • THis works great when pretty permalinks are not enabled. If we enable permalinks, how can we make sure that www.domain.com/section1 -> www.domain.com/wordpress/section1 without returning erro404 ? – Paris Char Aug 24 '14 at 22:21
  • Well I think I solved this problem. The .htaccess file in the /wordpress directory has to be edited, just after you enable pretty permalinks: The line `RewriteRule . /index.php [L]` should be changed to `RewriteRule . wordpress_subdir/index.php [L]` – Paris Char Aug 25 '14 at 14:34
0

And if that's not enough:

Two hints:

If you're not in a hosted environment (= if it's your own server and you can modify the virtual hosts, not only the .htaccess files), try to use the RewriteLog directive: it helps you to track down such problems:

# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On

My favorite tool to check for regexp:

http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)

Community
  • 1
  • 1
Olivier Pons
  • 15,363
  • 26
  • 117
  • 213