I just decided to put a sub domain on my directory, but the .htaccess rules I wrote don't apply for the subdomain.

Here are the code snippets, can anybody see what I am doing wrong here?

RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteRule ^web-directory/category/(.*)/(.*) web-directory/index.php?catid=$1&start=$2


RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteRule ^(.*)/(.*) 

The first one works fine, the 2nd one is no good. Any ideas?

Dani AI

Generated

Quick diagnosis based on ’s posts and ’s suggestion: the second rule fails because mod_rewrite does not match a full URL in a per-directory (.htaccess) context. In .htaccess the pattern sees only the request path (no scheme/host) and — important — it is relative to the directory that contains the .htaccess (no leading slash). If the subdomain uses a different DocumentRoot, rules in the original directory will never run for requests to the subdomain.

Practical fixes:

  • If the subdomain has its own docroot, put an .htaccess there and match the local path (e.g., ^category/...).
  • If the .htaccess must stay in a shared docroot, add a host check with RewriteCond %{HTTP_HOST} to target the subdomain.
  • Do not put the full URL into the left-hand side pattern. Use the RHS full URL only when an external redirect is intended.
  • Patterns in .htaccess must omit a leading slash. Make trailing slashes optional with /? if needed.

Example patterns (not copies of the originals above):

# In the main docroot: only rewrite when the Host is the subdomain
RewriteEngine On
RewriteCond %{HTTP_HOST} ^web-directory\.mcpmedia\.com$ [NC]
RewriteRule ^category/([^/]+)/?([0-9]*)$ /web-directory/index.php?catid=$1&start=$2 [L,QSA]
# In the subdomain's docroot (rules are relative to this directory)
RewriteEngine On
RewriteRule ^category/([^/]+)/?([0-9]*)$ index.php?catid=$1&start=$2 [L,QSA]

Troubleshooting checklist: confirm mod_rewrite is enabled and AllowOverride All is set for the directory, check for required Options permissions, enable rewrite logging (e.g., LogLevel rewrite:trace3) and inspect error_log, test with curl and a hosts-file entry to simulate the subdomain, and ensure dots in hostname patterns are escaped. For authoritative reference see the Apache mod_rewrite documentation.

Recommended Answers

All 2 Replies

no help? Anybody have any ideas?

I am not sure whether it works. Just give it a try and do let me know the result. :)

RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteRule ^web-directory/category/(.*)/(.*)/$ /web-directory/index.php?catid=$1&start=$2


RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteRule ^(.*)/(.*)/$ 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.