PDA

View Full Version : htaccess Help



phpmycoder
04-12-2009, 11:09 PM
Hello,
I am mainly a PHP programmer that is working on my personal website, www.phpmycoder.net (which I just bought for hostmonster!!). I'm working on the subdomain that will hold all my javascript, css, and images. This subdomain will be assets.phpmycoder.net. I am currently working on an htaccess file that will redirect all traffic that is not a request for an image, script, or stylesheet to my home page at www.phpmycoder.net. When I try to view an image on my assets subdomain I get a 500 server error that says that my htaccess is incorrectly coded...here is the source:

RewriteEngine On
RewriteCond %{REQUEST_URI} != ^(.*)/images/(.*)\.jpg$ [OR]
RewriteCond %{REQUEST_URI} != ^(.*)/images/(.*)\.gif$ [OR]
RewriteCond %{REQUEST_URI} != ^(.*)/css/(.*)\.css$ [OR]
RewriteCond %{REQUEST_URI} != ^(.*)/js/(.*)\.js$
RewriteRule ^(.*)$ http://www.phpmycoder.net/ [r=301]

It's also important to note that within the assets subdomain there are folders for the images css and javascript (called images, css, and js receptively). Could someone aid me in fixing my htaccess file??
Thanks!!!
PhpMyCoder

Falcon1986
04-13-2009, 07:19 AM
I am currently working on an htaccess file that will redirect all traffic that is not a request for an image, script, or stylesheet to my home page at www.phpmycoder.net.

Wouldn't it be easier to just redirect all links requesting files from the assets directory to the assets subdomain?

I utilize z as a subdomain from which I request images, CSS and Javascript files. There is also something similar set up for PDFs on the files subdomain. I used RewriteMatch in order to force a 301 redirect for any subdirectory requests to the subdomain.


RedirectMatch 301 ^/subdomain/(.*)$ http://subdomain.maindomain.tld/$1

I visited your website and noticed that at least your images are being loaded from the subdomain just fine.

phpmycoder
04-13-2009, 02:29 PM
Yes! I am so excited (I spent all night last night getting it up and online). Maybe I did a poor job of explaining what I'm trying to do. I don't need to redirect all the traffic from www.phpmycoder.net/assets to assets.phpmycoder.net (assets.phpmycoder.net is the subdomain that will host all my js, css, and images for everything on my site). What I'm trying to do is that since the assets subdomain only holds js, css, and image files there are no html files or 404 error pages. For this reason, I would like to redirect all traffic to assets.phpmycoder.net that is not a request for an image, js, or css file to my home page. The basic reason for this is so that you can't see a directory listing of the assets subdomain and instead of seeing a message like "This virtual host doesn't support directory listing" and whatnot, you would see my homepage (Giving me more traffic to the right pages of my site instead of to the error pages). Its also important to note that assets.phpmycoder.net/js holds js files, assets.phpmycoder.net/css holds css files, and assets.phpmycoder.net/images holds image files (Some are in folders below this such as images/navigation, images/indexpage, and more and I do not want them to not work). That was the purpose of my code (Below).

RewriteEngine On
RewriteCond %{REQUEST_URI} != ^(.*)/images/(.*)\.jpg$ [OR]
RewriteCond %{REQUEST_URI} != ^(.*)/images/(.*)\.gif$ [OR]
RewriteCond %{REQUEST_URI} != ^(.*)/css/(.*)\.css$ [OR]
RewriteCond %{REQUEST_URI} != ^(.*)/js/(.*)\.js$
RewriteRule ^(.*)$ http://www.phpmycoder.net/ [r=301]
I was going to place that htaccess code in my assets.phpmycoder.net domain to redirect all traffic to assets.phpmycoder.net not to images, css, or js files to my real home page, www.phpmycoder.net. Does this make my problem clearer? (Also sorry for the long post. I was trying to be as detailed as possible) :)

phpmycoder
04-13-2009, 06:28 PM
Problem fixed! I just messed with the code a little bit and found a working solution (I didn't realize that | in htaccess meant or!).