lisovaccaro
lisovaccaro

Reputation: 33956

.htaccess 'IF' in rewrite rule?

This is my rule:

RewriteRule ^([^/]+)(/.+)? /negocio$2.php?shopURL=$1 [L,QSA]

If $2 doesn't exist (URL doesn't have two slashes), I want to echo '/' instead of '.php'. So the condition becomes:

RewriteRule ^([^/]+)(/.+)? /negocio/?shopURL=$1 [L,QSA]

How do I do this or archive the same result?

Upvotes: 0

Views: 61

Answers (2)

anubhava
anubhava

Reputation: 785146

Replace your code with this:

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/?$ negocio/?shopURL=$1 [L,QSA]

RewriteRule ^([^/]+)(/.+?)/?$ negocio$2.php?shopURL=$1 [L,QSA]

Upvotes: 0

kclair
kclair

Reputation: 2224

Pretty sure this is what RewriteCond is for!

RewriteEngine on

RewriteCond %{REQUEST_URI} ^/([^/]+)(/.+)$
RewriteRule ^([^/]+)(/.+)? /negocio$2.php?shopURL=$1 [L,QSA]

RewriteCond %{REQUEST_URI} ^/([^/]+)$
RewriteRule ^([^/]+)(/.+)? /negocio/?shopURL=$1 [L,QSA]

Upvotes: 1

Related Questions