Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite and sub domain problem

mod_rewrite code breaks subdomain access

         

Roobik

9:36 am on Oct 23, 2008 (gmt 0)

10+ Year Member



Hi I have a problem with htaccess !
I have a some mod_rewrite in htaccess but now i can not access to my sob domains :(
can any one help me how i can solve this problem ?

this is my .htaccess code


Options All -Indexes
ErrorDocument 404 /404.php
FileETag MTime Size

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule ^sitemap\.xml$ feed.php?output_type=sitemap [L]
RewriteRule ^(.*)(\.html¦\.htm)$ index.php [L]
RewriteRule ^(.*)(\.rss¦\.atom¦\.txt)$ feed.php [L]
RewriteRule ^([^.]*)/?$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>

<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/gif "access plus 1 months"
ExpiresByType image/jpeg "access plus 1 months"
ExpiresByType image/png "access plus 1 months"
</IfModule>

[edited by: jdMorgan at 9:16 pm (utc) on Oct. 23, 2008]
[edit reason] Corrected code post formatting only. [/edit]

jdMorgan

1:52 pm on Oct 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is not clear.

Are these subdomains new?
Or did your subdomains stop working after you added this code?
Are the subdomains defined in your DNS zone file?
How did you 'create' the filespace for the subdomains - Did you use a control panel, or did you add code to do it)?

There are many ways to create and access subdomains, so we need more information.

Jim

Roobik

2:04 pm on Oct 23, 2008 (gmt 0)

10+ Year Member



Yes the subdomain is new ! And i create it with my host cpanel !
It workes when i remove the cod from htaccess ! but whit this cod i can not reach the sub domain !

jdMorgan

2:13 pm on Oct 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please give us a list of your "main" domain and the names of the new subdomains. Do not use your real domain name, but use "example" instead. What we need is a "map" like this:

example.com - main domain
www.example.com - www subdomain of main domain
abc.example.com - new subdomain
def.example.com - new subdomain

Jim

Roobik

2:26 pm on Oct 23, 2008 (gmt 0)

10+ Year Member



Thanks Jim

example.com - main domain
farsi.example.com - new subdomain

[edited by: jdMorgan at 2:34 pm (utc) on Oct. 23, 2008]
[edit reason] Please use example.com as requested. [/edit]

jdMorgan

2:37 pm on Oct 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, I had to edit your post. Please do not use 'real' URLs here. If I didn't edit in time, you may find that this thread now out-ranks your own site for searches on those domain names...

Do you use the "www" subdomain?
What are the (invalidly-coded) last two RewriteConds intended to do?

Jim

Roobik

3:04 pm on Oct 23, 2008 (gmt 0)

10+ Year Member



no i dont use " www " in subdomain !
I dont know ! when i remove the code from .httaccess i can reach the sub domain but with the code in .httaccess i get 404 error page !

jdMorgan

3:11 pm on Oct 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where did you get these two lines of code?

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Did you modify the order of this code? Or did you leave out the RewriteRule that must follow these two lines to make them valid?

There are multiple problems here, and if you cannot tell us what this code is supposed to do, then we cannot help you fix all of the problems. Are you running WordPress, by any chance?

Jim

Roobik

3:32 pm on Oct 23, 2008 (gmt 0)

10+ Year Member



I have a vivvo news installed in this hosting

jdMorgan

3:45 pm on Oct 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, what is the filepath to the vivvo news script?

Jim

[edited by: jdMorgan at 3:45 pm (utc) on Oct. 23, 2008]

Roobik

4:01 pm on Oct 23, 2008 (gmt 0)

10+ Year Member



soory ! :( what it mean file path ?!
I install it in my host root !

jdMorgan

6:15 pm on Oct 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is the full name of the file, then?

Roobik

6:35 pm on Oct 23, 2008 (gmt 0)

10+ Year Member



for example !
169.html is a file name of one news

jdMorgan

6:42 pm on Oct 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We need to know the name of the file on your server, not the URL. These are two different things.

Jim

Roobik

7:03 pm on Oct 23, 2008 (gmt 0)

10+ Year Member



All files is php !
For example index.php is the main file of vivvo CMS

jdMorgan

8:12 pm on Oct 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK. Since you already have existing rewrites to index.php, we will assume for now that the final two lines of your mod_rewrite code are no longer needed. If something still does not work after making changes, then perhaps you can give us enough information to figure out what might be missing.

All I know is that RewriteConds must be followed by a RewriteRule, and there is no RewriteRule following those two lines in your file. So that is an error.

I suggest the following changes to your file:


Options All -Indexes
ErrorDocument 404 /404.php
FileETag MTime Size
#
RewriteEngine on
#
# Redirect non-canonical hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC,OR]
RewriteCond %{HTTP_HOST} example\.com(\.¦\.?:[0-9]+)$ [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
#
# Skip the next four rules if the requested hostname is not exactly "example.com" or blank
RewriteCond %{HTTP_HOST} !^(example\.com)?$
RewriteRule .* - [S=4]
#
RewriteRule ^sitemap\.xml$ feed.php?output_type=sitemap [L]
#
RewriteRule ^([^.]+\.)+html?$ index.php [L]
#
RewriteRule ^([^.]+\.)+(rss¦atom¦txt)$ feed.php [L]
#
RewriteRule ^([^.]*)/?$ index.php [L]
#
# Set expires response headers for images
ExpiresActive on
ExpiresByType image/gif "access plus 1 months"
ExpiresByType image/jpeg "access plus 1 months"
ExpiresByType image/png "access plus 1 months"

Important: Replace all broken pipe "¦" characters with solid pipe characters before use; Posting on this forum modifies the pipe characters. They also may display differently due to differences in browser character-sets and/or character encodings.

The new "skip" rule causes the following four rules to be by-passed if the requested hostname (domain) is *not* your main domain. So those four rules will no longer be applied to any subdomains.

Jim

jdMorgan

9:14 pm on Oct 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could also add this rule after the very first rule to canonicalize requests for your subdomains as well:

# Redirect non-canonical subdomain hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com(\.¦\.?:[0-9]+)$ [NC]
RewriteRule (.*) http://%1.example.com/$1 [R=301,L]

Jim

Roobik

10:43 am on Oct 24, 2008 (gmt 0)

10+ Year Member



thanks jim
Now i have a problem for permission when i try to access the sub domain i get this error
Forbidden
You don't have permission to access / on this server.

But when i remove all codes in .htaccess it works normaly !

jdMorgan

12:58 pm on Oct 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have explicitly denied folder access using
 Options -Indexes 

If there is no index file in that directory, or if you have not declared its name using
 DirectoryIndex <index-filename.extension> 

then the 403 response is correct.

The "usual" configuration is to use Options -Indexes, but provide and declare an index file. In this case, the index file should be served, even with directory indexes disabled.

The purpose of Options -Indexes is to prevent visitors from seeing an index (a file listing) of all files in a directory when that directory does not have a defined index (HTML) page. This can be a security problem.

Jim

Roobik

8:41 pm on Nov 5, 2008 (gmt 0)

10+ Year Member



thank you JIM
I use the code and the problem solved but now i have a problem with www ! when i type www.example.com it redirect to example.com but some fature of my site dont work without www !
Is there any way to solve this problem ?!