Mobile app version of vmapp.org
Login or Join
Hamaas447

: Is it possible to mod_rewrite BASED on the existence of a file/directory and uniqueID? My site currently forces all non-www. pages to use www. Ultimately, I am able to handle all unique subdomains

@Hamaas447

Posted in: #Htaccess #ModRewrite #Php

My site currently forces all non-www. pages to use
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 example.com/john4, the server processes that request as: example.com?Agent=john4
Our requirements are:


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

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Hamaas447

2 Comments

Sorted by latest first Latest Oldest Best

 

@Ann8826881

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= [L]

10% popularity Vote Up Vote Down


 

@Pope3001725

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= [L]
</IfModule>

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme