Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite

Please tell me if i have this right

         

cynikalsam

7:15 pm on Jan 6, 2005 (gmt 0)

10+ Year Member



Ok, i have a page at

http://www.mysite.com/forum/page.php

I want to use this as the main index of my site, so people will see that page when they enter

http://www.mysite.com

I also have a list of blogs located at

http://www.mysite.com/forum/weblogs.php

I want people to see that list when they enter

http://www.mysite.com/blogs

So by looking at what other people have done with mod_rewrite, i made this code;

RewriteCond %{HTTP_HOST} www\.mysite\.com
RewriteRule ^$ http://www.mysite.com/forum/page.php [L]
RewriteCond %{HTTP_HOST} www\.myhost\.com/blogs
RewriteRule ^([^.]+)$ weblogs.php [L]

Will this work? If so, i just put this code somewhere in the .htaccess file in the public_html folder, right?

I'd really like to be sure before i try.

jdMorgan

9:26 pm on Jan 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



HTTP_HOST will contain, at most, the domain name and a port number, so you can't include a directory path in the pattern you want to match against HTTP_HOST.

You may also want to make sure the rules will work with or without "www".

If you want to match a request for "blogs" then that has to be in your pattern.

With that in mind, I'd suggest:


RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com
RewriteRule ^$ /forum/page.php [L]
RewriteCond %{HTTP_HOST} ^(www\.)?myhost\.com
RewriteRule ^blogs/?$ /forum/weblogs.php [L]

Jim

cynikalsam

9:47 pm on Jan 6, 2005 (gmt 0)

10+ Year Member



Thank you.

Will this affect any other pages in the /forum/ directory? For example, will /forum/index.php still function correctly?

Also, the weblogs.php list will be weblogs.php?dynamiccontent&user=x when you view a blog. Does that mean the url for the blog will be

http://www.mysite.com/blogs/?dynamiccontent&user=x
?

Thanks again for your help

jdMorgan

10:19 pm on Jan 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Will this affect any other pages in the /forum/ directory? For example, will /forum/index.php still function correctly?

Also, the weblogs.php list will be weblogs.php?dynamiccontent&user=x when you view a blog. Does that mean the url for the blog will be [mysite.com...]

You're asking me questions which I can't answer, because I don't know precisely how your site is set up. Realistically, the only way to find out is to test the code, either at a time when your server is least busy, or on a test server. If your site is always busy, then you should consider setting up a test server or creating a test subdomain on your existing server to help with situations like this.

You originally asked if your code was sound, and I pointed out a few syntax problems. Asking if your site will work with it goes well beyond the scope of a simple "Is this code OK?"-type question. So, I'm sorry, but I really don't know. :(

Jim

cynikalsam

10:53 pm on Jan 6, 2005 (gmt 0)

10+ Year Member



Thats cool. I tested it, but nothing happend. No error, no re-writing..

Here's the full .htaccess file

# -FrontPage-

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com
RewriteRule ^$ /forum/page.php [L]
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com
RewriteRule ^blogs/?$ /forum/weblogs.php [L]

IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName www.mysite.com
AuthUserFile /home/me/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/me/public_html/_vti_pvt/service.grp

And i put it in the public_html folder

cynikalsam

11:09 pm on Jan 6, 2005 (gmt 0)

10+ Year Member



//EDIT

Ok, everything seems to be working fine, except the background image doesnt load. I'll try to figure this out, but if im missing anything in my code, please let me know.

Thanks again for all your help :)

jdMorgan

2:25 am on Jan 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Relative links, and in this case, relative image links of the form <img src="some_path_to_image_relative_to_script_directory.gif"> often will not work if the script was reached by rewriting. The link will need to be changed to <img src="/some_path_to_image_relative_to_web_root.gif"> in order to work properly.

Jim