php - .htaccess conflict between two rewrite rule


in my website two rewrite rule are conflicting with each other i have url for my users like= and all my website pages open like

now here is htaccess file rules

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?user=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?user=$1

Now only this rule works because its loaded first =

RewriteCond %{REQUEST_FILENAME} !-d

And if i put profile rewrite rule above

RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?user=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?user=$1 (then this works)

and this doesnt

RewriteCond %{REQUEST_FILENAME} !-d (does not work)

What is the problem in htaccess rule?




You should check for presence of.php file before adding.php extension:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/?$ profile.php?user=$1 [L,QSA]

People are also looking for solutions to the problem: php - fast session connect using http prebind in openfire


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.