1
votes

My root already has all the css and image files I require

  • www.example.com (my domain)
  • www.example.com/css/style.css (my styles)

On my hosting, my sub domain has to live inside a folder

root folder 
  public_html/
    index.php
    css/
      style.php
  subdomains/
      admin/
        .htaccess
        index.php

How can I use mod_rewrite in my subdomain to redirect requests for css into my root folder?

FINAL SOLUTION

Thanks! I used Shikhar's answer and modified it to also work with images and js.

  RewriteCond %{HTTP_HOST} admin.example.com
  RewriteCond %{REQUEST_URI} [css|images|js]/(.*)\.(.*)
  RewriteRule (.*) http://www.example.com%{REQUEST_URI} [R=301,NC,L]
2

2 Answers

2
votes

RewriteCond %{HTTP_HOST} xyz.example.com

RewriteCond %{REQUEST_URI} css/style.css

RewriteRule (.*) http://www.example.com%{REQUEST_URI} [R=301,NC,L]

This requires redirect though.

2
votes

If you have access to the box, why not just create a symbolic link from the subdomain folder to the root folder. You should be able to do this through your file manager or though a shell prompt on the box.