Forum Moderators: phranque

Message Too Old, No Replies

Help with this mod rewrite / htaccess

mod rewrite, htaccess

         

delirium

2:40 am on Jun 9, 2010 (gmt 0)

10+ Year Member



Hello everyone :)

I am hoping that someone can help me resolve this thing I have been sitting over for two days now.

I am trying to get a url that looks like this

--http://mydomain.com/category/title

to work like this

--http://category.mydomain.com/title

Wild card sub domains on the Apache hosting account I use are enabled.

I DID manage to get this to work

--http://category.mydomain.com

But I can't seem to get the title in there too.

Can anyone see the problem with this mod rewrite? I would really appreciate some help or a keen eye to tell me how to get this to work.

RewriteEngine On
Options +Indexes
Options +FollowSymlinks

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.mydomain\.com$ [NC]
RewriteCond %1 !^(www|ftp|mail)$ [NC]
RewriteCond $1 !^(([A-Z-a-z-0-9_(0-9)])\.php)$ [NC]

RewriteRule ^$ /article.php?category_slug=%1 [QSA,L]
RewriteRule ^\?([A-Z-a-z-0-9_(0-9)]*) article_detail.php?category_slug=%1&article_slug=$1 [NC]


Thank you!

g1smd

7:09 am on Jun 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



$1 in the RewriteCond will be undefined.

The RewriteConds apply only to the single RewriteRule that follows them.

If you wish to have the same RewriteConds apply to a different RewriteRule you have to duplicate those lines of code.

Add the [L] flag to every RewriteRule line.

delirium

7:35 am on Jun 9, 2010 (gmt 0)

10+ Year Member



Is this what you mean?

RewriteEngine On
Options +Indexes
Options +FollowSymlinks

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.mydomain\.com$ [NC]
RewriteCond %1 !^(www|ftp|mail)$ [NC]
RewriteRule ^$ /article.php?category_slug=%1 [QSA,L]

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.mydomain\.com$ [NC]
RewriteCond %1 !^(www|ftp|mail)$ [NC]
RewriteCond $1 !^(([A-Z-a-z-0-9_(0-9)])\.php)$ [NC]

RewriteRule ^\?([A-Z-a-z-0-9_(0-9)]*) /article_detail.php?category_slug=%1&article_slug=$1 [QSA,L]


... I get exactly the same result as with the code before... I actually do get $1,, I can't seem to get %1
My brain kind of operates by example :s,, I am not a BIG expert on mod_rewrite


Maybe this would be a simpler way to ask what I need..

How could I turn this --http://mydomain.com/script.php?val1=is1&val2=is2

into this..

--http://is1.mydomain.com/is2/

I can't find a working example anywhere,,

I really don't mean to be a pest with this... I hope someone can help :)

jdMorgan

5:33 pm on Jun 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are several unspecified requirements, and your single example URL is too short and generic. This makes decoding some of your patterns impossible. But re-wording your question to comport with actual function:

> How can I rewrite the requested URL [is1.example.com...] to the filepath /script.php?val1=is1&val2=is2 ?

would result in code similar to

Options +FollowSymlinks +Indexes
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com [NC]
RewriteCond %1 !^(www|ftp|mail)$ [NC]
RewriteRule ^$ /article.php?category_slug=%1 [QSA,L]
#
RewriteCond $1 !\.php$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com [NC]
RewriteCond %1 !^(www|ftp|mail)$ [NC]
RewriteRule ^([a-z0-9_\-]+)/$ /article_detail.php?category_slug=%1&article_slug=$1 [NC,QSA,L]

Jim

[edited by: jdMorgan at 9:41 pm (utc) on Jun 9, 2010]

delirium

6:20 pm on Jun 9, 2010 (gmt 0)

10+ Year Member



Thank you jdMorgan,,

I know my sample is generic. I wanted to keep it simple. Your sample works. I will handle the details. All along I kept spinning around the same idea,, but couldn't get it right. I understand now. I appreciate it very much.

Thank you again.