Mod_rewrite - addon domain

Hey. Sorry to ask another mod_rewrite question, this forum is filled with them. I’ve had a look around to see if I could find the answer but failed.

I’m trying to setup a rewrite for one of my addon domains:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?myaddondomain\.net$ [NC]
RewriteRule ([0-9]+)/(.*)/$ index.php?page_id=$1

So I want myaddondomain.net/3/page-title/ to go to index.php?page_id=3

I have this in the .htaccess file which is in my “main” domain folder (the addon domain has a folder in the main domain folder - I’m with bluehost).

This is not working, I get 401 file not found error.

Any advice would be awesome.

Thanks!

Hi NP!

Thanks for looking around first!

I’m not sure why you didn’t find a few things “wrong” with your mod_rewrite among the review threads, though.

First, the addon domain has its own directory structure - generally at the main domain’s {addondomain} subdirectory. What that means to you is that any request to the addon domain will (okay, SHOULD - unless you parked it on top of the main domain) bypass the main domain’s .htaccess file.

Options +FollowSymLinks
# Your host should already have this in the httpd.conf - if mod_rewrite is enabled.
# Check on mod_rewrite being enabled by using the simple test in my signature

RewriteEngine on
# :tup:  That ensures that mod_rewrite is NOT in comment mode

RewriteCond %{HTTP_HOST} ^(www\\.)?myaddondomain\\.net$ [NC]
# :tup: checking on the addon domain name - but that restricts the
# following from acting on the maindomain/subdomain-directory request
RewriteRule ([0-9]+)/[COLOR="Gray"](.*)/[/COLOR]$ index.php?page_id=$1 [COLOR="Red"][L][/COLOR]
# Why bother capturing the "garbage" after the first /
# (unless you will accept 0// or ...)?
# What?  No Last flag!  Horrors! :rolleyes:
# I KNOW your PHP won't work if you don't terminate a statement - 
# so don't do that to mod_rewrite!

Okay, MINOR nags about your code as, in general, it appears that you know what you’re doing (with the exception of the :kaioken: EVERYTHING :kaioken: atom - (.*) which IS intended to match no/all garbage so it’s only purpose is to force two /'s after your page_id digits).

Regards,

DK