Forum Moderators: phranque
I am going to set up some subdomains, so I think it's best to ask for advices first.
I would like to ask about what the best practice with the location of subdomain is. Through what I have learned, there are three possible ones (on same server):
public_html/subfolder/
subfolder outside public_html
subfolder point to public_html but got mod_rewrite to some function on index.php page.
Assuming that I am correct, I choose the 3rd approach as the contents on subdomain and domain have some similarities and designs and they need to share the index.php. What are potentials problem of this approach (broken links, duplicate contents, etc.)?
Or is it better to use the other approaches? And if so how should I use them?
With the 3rd approach, I use mod_rewrite to rewrite the subdomain to index.php?do=smt:
RewriteCond %{HTTP_HOST} !^localhost [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.localhost
RewriteRule ^$ /index.php?do=%1 [NC,L] Is that OK?
Btw, on my localhost, I found: "Options not allowed here" in the error log when I access [sub.localhost...] but the options work well with [localhost....] How can I fix this?
Oh, the last thing is, I try this: [webmasterworld.com...] but it does nothing. Is it too old or something? None of the RewriteRule work :S
Thank you! Please excuse my long post!
The "Options not allowed here" error sounds like it could be a coding error (where is this "Options" statement, what does it say, and are you sure you need it?), or it could be a matter of having "AllowOverride none" set in the server configuration for the subdomain. (You could simply add the subdomain as an alias servername in the main domain's configuration section, so they would both share all settings).
Jim
About the options, those lines appear at the top of my .htaccess, with the following contents:
Options All -Indexes
Options +FollowSymLinks
and the below lines:
<Files "config.php">
Order Allow,Deny
Deny from All
</Files>
<Files "common.php">
Order Allow,Deny
Deny from All
</Files>
caused "order not allowed here".
Well I just want to limit the access to config file as well as viewing the index of a folder.
After changing AllowOverride to none it now works but it doesn't limit the access to common.php when I navigate to [sub.localhost...] Navigate to localhost/common.php fires a correct 403.
Btw, I asked about this topic too: [webmasterworld.com...]
Would you mind helping me with it also? Thank you a lot!
AllowOverride specifies what Options in .htaccess can override the inherited server-level configuration. If "Options" isn't allowed to override by your server configuration's AllowOverride setting, then you cannot use the "Options" directive in .htaccess, and you will get the "Options not allowed here" error; the only options that will then be allowed in .htaccess code will be the options defined at the server or virtualhost level.
"Options +FollowSymLinks" is redundant if it follows "Options All -Indexes", because "All" includes "FollowSymLinks" (among the many other options it includes).
The code in the thread you cited was thoroughly tested before posting, and it works quite well and is in use today on (at least) hundreds of servers. But as it states in the text of the article, that code is not intended to be used without at least a couple of days of study; It is not trival, and you cannot just take a piece out here and there and use it. You shouldn't use any of it if you don't understand all of it...
Jim
About that thread, I was actually using about 2 rules, and one of them was:
# Redirect direct client requests for "<anything>/index.php" to "<anything>/"
RewriteCond %{ENV:myURI} ^(/([^/]+/)*)index\.php [NC]
RewriteRule . - [E=qRed:yes,E=myURI:%1] It didn't work on my localhost (I know that code works, it's just my problem :) ), so I used the usual way:
# Redirect direct client requests for "<anything>/index.php" to "<anything>/"
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://localhost/$1? [R=301,L]
# And it works. If I use env variable it does nothing. mod_env is loaded. And the .htaccess looks like:
ErrorDocument 404 /errordocs/404error.php
ErrorDocument 403 /errordocs/404error.phpOptions All -Indexes
Options +FollowSymLinks -MultiViews
RewriteEngine On
# Redirect direct client requests for "<anything>/index.php" to "<anything>/"
RewriteCond %{ENV:myURI} ^(/([^/]+/)*)index\.php [NC]
RewriteRule . - [E=qRed:yes,E=myURI:%1]
Thanks for your time!
That code is a "complete package," and must be understood in its entirety before anything can be removed or any 'pieces' of it can be used. In fact, it's not worth doing unless more than a few rules are used; There is some 'overhead' in the setup section which should be amortized over more than just a few functions.
The purpose of that code is to make many corrections (if needed) to a requested URL, all at once, and do a single redirect at the end to avoid stacked/chained/multiple redirects, as explained in the text. It is over-complicated if you only want to do a few corrections, and too difficult for most people as well.
Jim
We need to change this line, right:
RewriteRule .? http://localhost%{ENV:myURI}%{ENV:myQS} [R=301,L] (localhost is formerly "example.com")
And add some conditions? Please enlighten me, thanks!