how to write rewrite

only1wizard
only1wizard used Ask the Experts™
on
How do i rewrite this url http://www.example.com/blog/index.php to read in address bar as http://blog.example.com/index.php?

thanks in advance for your help!


1 # Use PHP5CGI as default$$
  2 AddHandler fcgid-script .php$$
  3 $$
  4 DirectoryIndex index.php$$
  5 $
  6 Options -Indexes +FollowSymLinks$$
  13 RewriteEngine on$
 14 $
 21 RewriteCond %{HTTP_REFERER} !^http://www.example.com/.*$      [NC]$
 22 RewriteCond %{HTTP_REFERER} !^http://www.example.com/blog/$      [NC]$
 23 RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]$

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
mod_rewrite does not serve this purpose. You would need something like mod_seo (Helicon).
Top Expert 2010

Commented:
Or you could simply add a new name based Virtual host definition, for "blog.example.com/ to the httpd.conf, with it's  DocumentRoot set to the B.../blog/ directory.

Author

Commented:
i already have a sub domain named blog.example.com

how would the virtual host benefit me?

when this is what im trying to achieve is this.

when i go to url http://www.example.com/blogs/blogs.php?BlogId=1&FriendId=1

rewrite that url to http://blog.example.com/blogs.php?BlogId=1&FriendId=1

thanks in advance for your help!
AdamSenior Developer
Commented:
To rewrite the page name, you can use something like this:

RewriteCond %{HTTP_HOST} ^blog\.example\.com$ [NC] <br>  
RewriteRule ^blog/blogs.php$ /blogs.php [NC,L]

This will make the file /blogs/blogs.php appear at the URL /blogs.php, but only for the blog.example domain

To change the domain name, you'll need to do a 301 redirect to move the user onto the other site:

RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] <br>  
RewriteRule ^blog/.? http://blog.example.com%{REQUEST_URI} [R=301,L]  

This will take the user from www.example.com to blog.example.com if the bath starts with /blog/
this is what i have working this is in my subdomain folders .htaccess

356 RewriteCond %{HTTP_HOST} !^blogs\.only1wizard\.com$
357 RewriteRule (.*) http://blogs.only1wizard.com/$1 [L,R=301]$
358 $

thanks for your help though!

Author

Commented:
Thanks for your help!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial