Forum Moderators: phranque

Message Too Old, No Replies

using rewrite rule multiple times

         

macdar

4:00 am on Sep 10, 2004 (gmt 0)

10+ Year Member



Hi,
I need to use simple rewrite rule:
RewriteRule ^something-(.*).html$ /index.php?pg=$1,

but the problem is I have about 100 subdomains, and I need to use it for every single subdomain. I could upload the .htaccess file to each sudirectory, but I'm sure there must be an easier way to handle it.
I'd like to have one .htaccess file in my root directory that will handle all subdomains.

thanks.

jdMorgan

4:11 am on Sep 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



macdar,

If your subdomains are rewritten to subdirectories of your main account, then it should work. If they are aliased, then you could remove that alias and use a rewrite instead. It all depends on *how* you map your subdomains to subdirectories.

The thing to remember is that in order for an .htaccess file on your root directory to be processed, it must be in the server filepath of the requested resource (page, image, script, etc.). The server traverses that path and executes each .htaccess file it finds as it resolves the URL to a filename.

Jim

macdar

5:12 am on Sep 10, 2004 (gmt 0)

10+ Year Member



Thanks for your response. Yes, my subdomains are rewritten to subdirectories of my main acount.

Can you tell me how should I create the .htaccess file to handle my subdomains?

thanks.

jdMorgan

5:32 am on Sep 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, if the subdomain has already been rewritten into the URL-path as a subdirectory, then you'd back-reference it with $1 and move the page name to $2. This new rule would have to go after the rule that rewrites subdomains to subdirectories, if that is also done in your root .htaccess file, and *that* rule should not have the [L] flag appended.

If you are doing the subdomain->subdirectory rewrite in httpd.conf, then you' also want to move this new rule into httpd.conf; otherwise it will be bypassed (And note the subtle difference in the RewriteRule pattern between .htaccess and httpd.conf - the pattern in httpd.conf must start with a slash).


RewriteRule ^([^/]+)/something-([^.]+)\.html$ /$1/index.php?pg=$2 [L]

Assuming that subdomain.example.com/something-widget.html has already been rewritten to example.com/subdomain/something-widget.html, then the above new rule will rewrite that to example.com/subdomain/index.php?page=widget

Jim

macdar

6:14 am on Sep 10, 2004 (gmt 0)

10+ Year Member



hmmm...seems to me that things became more complicated that I thought.
Let me say what I'm trying to do. I'm new one to apache. I need to use rewrite rule for each of m subdomains as I stated before.

I decided to look up that forum, and I found something like this:
rewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com
at [webmasterworld.com...]

Then I thought I could use it somehow in my .htaccess:
rewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com
RewriteRule ^something-(.*).html$ /index.php?pg=$1

I don't have access to the httpd.conf file. All I can do is to operate on the .htaccess file. I was tring to avoid uploading that .htaccess file one by one to my subdomains.

Now I have something like this:
subdomain.domain.com/index?pg=1
but I need
subdomain.domain.com/index1.html

Hope this make it simple.

thanks!