Search Engine Optimization > Webmaster World > mod_rewrite URL and SEO
mod_rewrite URL and SEO
Posted by ajam4@op.pl on January 3rd, 2006

Hi!!

I was searching answer for ma question everywhere but I couldn't find
it, so please HELP ME.

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) so
I added this code to .htaccess file in main directory:

Code:

RewriteCond %{HTTP_HOST} !^www\.sub\.domain\.com$
RewriteCond %{HTTP_HOST} ^(.*)sub\.domain\.com$
RewriteRule ^site/([0-9]+)$ http://sub.domain.com/index.php?section=$1
[L]



but this code doesn't work. Please help me, what's wrong whith this
code?

Thanks in advance,

Barcin

Posted by Justin Koivisto on January 3rd, 2006

ajam4@op.pl wrote:
If HTTP_HOST is *not* www.sub.domain.com

AND HTTP_HOST *ends* with sub.domain.com

With this rule, you should expect to see requests like:
http://sub.domain.com/site/7
http://mysub.domain.com/site/7
http://another.sub.domain.com/site/7

All be redirected (because of the complete URL) to:
http://sub.domain.com/index.php?section=7

Therefore, the browser's location bar should change...

What exactly isn't working - or maybe I should ask what is happening?

--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com

Posted by barcin on January 3rd, 2006

I get lost.

I'd be grateful for help.

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:

Code:

RewriteCond %{HTTP_HOST} ^sub\.domain\.com [NC]
RewriteRule ^site/([0-9]+),([0-9]+)$
http://sub.domain.com/index.php?section=$1&article=$2 [L]

RewriteCond %{HTTP_HOST} ^sub\.domain\.com [NC]
RewriteRule ^site/([0-9]+)$ http://sub.domain.com/index.php?section=$1
[L]

but when I request: http://sub.domain.com/site/39 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

P.S.
sorry for multiposting but I'm desperate ;(

Posted by Justin Koivisto on January 3rd, 2006

F'up to: alt.apache.configuration

barcin wrote:
Is the DocumentRoot of sub.domain.com the same as domain.com?

In the .htaccess file try something like this (untested):

RewriteCond %{HTTP_HOST} (.*)\.sub\.domain\.com
RewriteRule ^site/([0-9]+)(,([0-9]+))?$ index.php?section=$1&article=$3
[L,NS]

Also, be sure that this rule is above any similar rules in the file that
do not use the RewriteCond statement for it's domain...

--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com

Funbolt.com - Entertainment portal, wallpapers, sexy celebs