Sign up ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

My site currently forces all non-www. pages to use www.

Ultimately, I am able to handle all unique subdomains and parse correctly but I am trying to achieve the following (ideally with mod_rewrite):

When a consumer visits, the server processes that request as:

Our requirements are:

  • The URL should continue to show even though it was redirected to

  • If a file (of any extension OR a directory) exists with the name, the entire process stops an it tries to pull that file instead:

    For example: would pull up ( if file.php existed on the server. would go to if the pages directory exists).

share|improve this question

migrated from Feb 22 '11 at 23:26

This question came from our site for system and network administrators.

2 Answers 2

Try this (untested)

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?Agent=$1[L]
share|improve this answer
RewriteBase in this case is not necessary. The code continues to fail (although from looking through your suggestion it seems it should work. – JM4 Feb 23 '11 at 16:30

If you turn on MultiViews, you can do this, as it will search for request-uri.* first before running the RewriteRule.

Options +MultiViews
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?Agent=$1 [L]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.