Take the 2-minute tour ×
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 www.site.com/john4, the server processes that request as: www.site.com?Agent=john4

Our requirements are:

  • The URL should continue to show www.site.com/john4 even though it was redirected to www.site.com?index.php?Agent=john4
  • 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: www.site.com/file would pull up (www.site.com/file.php if file.php existed on the server. www.site.com/pages would go to www.site.com/pages/index.php if the pages directory exists).

Thank you ahead of time. I am completely at a crapshot right now.

share|improve this question

migrated from serverfault.com 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]
</IfModule>
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

 
discard

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.