Home > Net >  RewriteEngine Conflicting with each other
RewriteEngine Conflicting with each other

Time:08-12

Here is my code:

RewriteEngine ON

RewriteRule ^upload uploadArea.php [QSA,L]

RewriteRule ^u/([0-9a-zA-Z] )/uploads uploads.php?user=$1 [QSA,L]

I want to make domain.com/upload to access uploadArea.php
and domain.com/u/user_id/uploads to access uploads.php?user=user_id

But somehow, both domain.com/upload and domain.com/u/user_id/uploads URLs are accessing uploadArea.php file.

What is the actual problem? Also suggest any better way to do this.

CodePudding user response:

With your shown samples please try following .htaccess rules file. Make sure to place your .htaccess file along with your uploads.php file.

Also make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
##Internal rewrite rules for without query string.
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^upload/?$ [NC] uploadArea.php [NC,L]

##Internal rewrite rules for with query string.    
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^u/([^/]*)/uploads?$ [NC] uploadArea.php?user=$1 [QSA,NC,L]
  • Related