Forum Moderators: phranque
I have a hosted server. I have one main domain. There is some website under this domain. i'm using mod_rewrite to have SEO URL's so insted domain.com/index.php?section=5 I have domain.com/site/1. All mod_rewrite rules are in .htaccess file.
Using cPanel I've created subdomain sub.domain.com. There is a different website under this domain, but i want to have also SEO URL's, (sub.domain.com/site/2 goes to sub.domain.com/section.php?section=2)
I only want two rules for my subdomain:
RewriteRule ^site/([0-9]+),([0-9]+)$ index.php?section=$1&article=$2 [L]
RewriteRule ^site/([0-9]+)$ index.php?section=$1 [L]
first is for displaying articles, second for displaying section content.
index.php file is in subdomain.
so my code should look like this:
RewriteCond %{HTTP_HOST} ^sub\.domain\.com [NC] RewriteRule ^site/([0-9]+),([0-9]+)$ [sub.domain.com...] [L]
RewriteCond %{HTTP_HOST} ^sub\.domain\.com [NC] RewriteRule ^site/([0-9]+)$ [sub.domain.com...] [L]
but when I request: [sub.domain.com...] I get message
The requested URL /site/39 was not found on this server.
So please, help me, how to write code to make it work
Best regards
barcin
Welcome to WebmasterWorld!
There are three problems at three different levels. First, the code you posted won't work because you must have a newline between the directives.
Second, you cannot use a canonical URL (http://sub.domain.com...) for an internal redirect. If given a canonical URL and no [R] flag, Apache will default to a 302-Found external redirect. This 'exposes' your subdirectory and dynamic URLs to your visitors, which is not what you want. So, the RewriteRule must use a local URL-path.
RewriteCond %{HTTP_HOST} ^sub\.domain\.com [NC]
RewriteRule ^site/([0-9]+),([0-9]+)$ /index.php?section=$1&article=$2 [L]
#
RewriteCond %{HTTP_HOST} ^sub\.domain\.com [NC]
RewriteRule ^site/([0-9]+)$ /index.php?section=$1 [L]
You should place the code above inside the subdirectory folder used to store the new domain's files, and adjust it to work in that location. You will probably not need the RewriteConds at all.
I may be wrong about how your control panel creates subdirectories for new domains, but check this and let us know.
Jim
First of all, you're the first person and this is the first forum (I've posted this problem on many) who gave me good answer. so Thank you very much ;)
And my comments:
In .htaccess I have line breaks, here, it's been lost during copy-paste operation.
Second, I dont't understand the problem with redirection, internal and external. It works with [sub.domain.com...] and with /index.php?. And in an adress bar in a browser I still have /site/ adress, so no one can see my subdirectory. Am I right or wrong? ;)
Third, I was told by my server administrator and few people from different forums, that the mod_rewrite code for subdomains created by virtualhost must be in the main directory. When I was completely desparate this evening (I've lost two days for this problem) I moved this code to the subdirectory and... victory, It started working.
I think my problem is solved but if you think that there is a safer solution, be my guest. I'm open for all comments. ;)
Best regards
Barcin