Hostname shown twice in post url rewrite path = 404 error


Wrestling with a slight issue using mod_rewrite and .htaccess

Using shared hosting with a major provider (broad with a race car and all that).

Using a subdomain for development. Apache is 2.2

Have an incoming URL formatted as:

and looking to rewrite it as:

.htaccess (housed within the ‘activate’ sub-directory alongside process.php)

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^subscription/x/(.*)/y/(.*)/?$ process.php?x=$1&y=$2 [L]

Please Note: The (.*) catch-all syntax will be replaced with proper regex once this script is confirmed to work. You might factor for this when bringing the hammer down for improper use of syntax.

Browser reports the following:

The requested URL /dev/dev/newsletter/activate/process.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

The issue being wrestled with is that ‘dev’ shows up twice in the URL path.

I’m at a loss to explain its presence there, or how to remove it.

Ideas and/or critical review are welcomed.

~ David

Hi David,

Normally, the repeat of the domain in the redirection is a signal that Apache needs to be restarted.

This, however, does not appear to be the full repeat so it may have something strange to do with the subdomain. In any case, a restart may help.

GOOD NOTE! I routinely attack the indiscriminate use of (.*) (in this case, (\d+) would be preferred) so you’ve escaped my rath! ;D

There are three more comments:

  1. Options +FollowSymLinks really should be in the httpd.conf already (not necessary in .htaccess).

  2. I so rarely seen the correct ‘on’ (vs ‘On’) that you get kudos for that! I believe that Apache is smart enough to correct the cap error but it doesn’t need to prove it’s smarter than you are (because it can’t).

  3. Older versions of Apache required a leading / (when IN subdirectories of the domain) so I’d try either a hard leading / or a soft leading / (that’s /?) before subscription.

Please let me know how that works out.



This is what seems to have finally resolved the matter:

RewriteEngine on
RewriteBase /newsletter/activate/
RewriteRule ^subscription/x/(.*)/y/(.*)/?$ process.php?x=$1&y=$2 [L]

It works in the sense that there is no repeated host name in the rewritten URL, and process.php receives the variables and processes them without a hitch.

Thought this might be of interest.

Thank you very much for the time and ideas.

~ David

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.