.htaccess - htaccess, www redirect fake subdirectory -


common problem, complicated me.

here requirements trying meet:

  1. the root url http://example.com should redirected http://www.example.com
  2. all urls http://example.com/c/1234567890 should redirected http://www.example.com/c/1234567890 (notice "c" fake subdirectory)
  3. when entered http://example.com/index.php 1 should redirected http://www.example.com (no trailing slashes)
  4. on top of i'm trying failing secure subfolder "xy" direct access exept php files in root , javascript files.

i searched lot , tried lot of rewrite conditions , rules, htaccess+regex planet me. :/ sorry if duplicate…

these in htaccess file in document root. turn on rewrite engine

rewriteengine on 

for 1 , 2: redirect "www" if root request or request /c/(something)

rewritecond %{http_host} ^example\.com$ [nc] rewriterule ^(c/.+)?$ http://www.example.com%{request_uri} [l,r=301] 

for 3: redirect direct requests /index.php /

rewritecond %{the_request} ^[a-z]{3,9}\ /index\.php rewriterule ^ / [l,r=301] 

for 4: forbid direct access in /xy/ directory.

rewritecond %{http_referer} !http://(www\.)?example\.com/ [nc] rewriterule ^xy/ - [l,f] 

Comments