views:

763

answers:

3

Hello,

I am working in expression engine CMS and I have some rewrite code to remove the index.php from the URL but on some of my URLs I want to remove the directory /site/ before the file name.

Like I have /site/pennsylvania_attorneys.html

I want to remove the site part and just have it read /pennsylvania_attorneys.html

The current mod rewrite code I have now is:

RewriteEngine on
RewriteCond $1 !^(images|css|themes|tools|admin|inc|js|cgi-bin|swf|themes|pennsylvania_attorneys_tpl\.html|license\.txt|attorney-tpl\.html|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]

Any ideas?

A: 

Well you could cut all this and simply do this:


RewriteEngine On
RewriteRule ^.*$ site/$0 [L,QSA]

And you don't have to "remove" the index.php from the URLs, you can simply never put it there. Shall work just fine.

Havenard
A: 

Thanks but that didn't work, when I removed mine it went to blank page; I tried adding your code but it didn't remove the site/

RewriteEngine on RewriteCond $1 !^(images|css|themes|tools|admin|inc|js|cgi-bin|swf|themes|pennsylvania_attorneys_tpl.html|license.txt|attorney-tpl.html|favicon.ico|robots.txt|index.php) [NC] RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteRule ^.*$ site/$0 [L,QSA]

Kevin Evans
Please use the comment below the answers to comment on that answer.
Gumbo
Sounds like you are expecting it to do something it is not meant to do. mod_rewrite will not change the URL. It will not provide any URL to the user (unless you program it to). The objective of mod_rewrite is to translate the URL given from the user to the Apache. Besides that, your RewriteCond is broken, this $1 there makes no sense.
Havenard
@Havenard: `$1` refers to the match of the first group of the corresponding `RewriteRule` directive.
Gumbo
A: 

Try these rules:

RewriteCond %{THE_REQUEST} ^GET\ /site/
RewriteRule ^site/(.*) /$1 [L,R=301]
RewriteRule !^site/ site%{REQUEST_URI}

That will redirect any request of /site/… externally to just /… and reappend it internally if it’s missing on request.

Gumbo