Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 31617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:38:00+00:00 2026-05-10T13:38:00+00:00

I’m trying to redirect all requests to my domain to another domain using mod_rewrite

  • 0

I’m trying to redirect all requests to my domain to another domain using mod_rewrite in an Apache 2.2 VirtualHost declaration. There is one exception to this — I’d like all requests to the /audio path not to be redirected.

I’ve written a RewriteCond and RewriteRule to do this but it’s not quite right and I can’t figure out why. The regular expression contains a negative lookahead for the string "/audio", but for some reason this isn’t matching. Here’s the definition:

RewriteEngine on RewriteCond %{HTTP_HOST} ^(.*\.)?mydomain\.net(?!/audio) [NC] RewriteRule ^(.*)$ http://www.newdomain.example [L,R=301] 

If I change the RewriteCond to:

RewriteCond %{HTTP_HOST} ^(.*\.)?mydomain\.example/(?!audio) [NC] 

(i.e. put the forward slash outside of the negative lookahead part) then it works, but the downside of this is that requests to mydomain.example without a trailing slash will not be redirected.

Can anyone point out what I’m doing wrong?

Here are the rules:

<VirtualHost *:80> ServerAdmin me@mydomain.example DocumentRoot "/var/www/mydomain.example/htdocs" ServerName www.mydomain.example ServerAlias mydomain.example  RewriteEngine on RewriteCond {REQUEST_URI} !^/audio RewriteRule ^(.*)$ http://www.newdomain.example [L,R=301] RewriteLog logs/mod_rewrite_log RewriteLogLevel 3  ErrorLog logs/error_log CustomLog logs/access_log common </VirtualHost> 

Thanks @mercutio — that makes perfect sense but it still doesn’t seem to work.

Here’s what the mod_rewrite log says when I make a request to http://mydomain.example/audio/something.mp3:

(2) init rewrite engine with requested uri /audio/something.mp3 (3) applying pattern '^(.*)$' to uri '/audio' (2) rewrite '/audio' -> 'http://www.newdomain.example/' (2) explicitly forcing redirect with http://www.newdomain.example (1) escaping http://www.newdomain.example for redirect (1) redirect to http://www.newdomain.example [REDIRECT/301] 

Since the REQUEST_URI does start with /audio I would expect the RewriteRule to be ignored.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T13:38:00+00:00Added an answer on May 10, 2026 at 1:38 pm

    The HTTP_HOST only contains the host name, not the path of the URL requested.

    RewriteCond %{REQUEST_URI} !^/audio 

    Should be all you need.

    Further, you can get debug info from the rewrite engine with the following, which is really useful to see how your conditions and rules are being matched:

    RewriteLog /path/to/log/file RewriteLogLevel 3 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 77k
  • Answers 77k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Don't guess, measure. Try the various methods and see which… May 11, 2026 at 3:21 pm
  • added an answer you could do this: -- add 'loopback' linkedserver if exists… May 11, 2026 at 3:21 pm
  • added an answer To understand what's happening, you should try to run it… May 11, 2026 at 3:21 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.