htaccess condition and rule.
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

I need a htaccess rule

condition exclude

condition exclude (slash at the end)

rewrite to

rewrite to

rewrite to

rewrite to

awarded to Titus

Crowdsource coding tasks.

2 Solutions

Tell me if this works

RewriteEngine On
RewriteRule ^(\?p=)?demo([^-]*)\-(.*) ?p=demo$2\ $3 [N]
test here, check updated bounty.
feligosky 9 months ago
Winning solution

Try this:

RewriteEngine On
RewriteBase /
RewriteRule ^([^\/-]+)$ ?p=$1 [R=301,L]
RewriteRule ^([^\/-]+)\-([^\/-]+)$ ?p=$1+$2 [R=301,L]
RewriteRule ^([^\/-]+)\-([^\/-]+)\-([^\/-]+)$ ?p=$1+$2+$3 [R=301,L]
RewriteRule ^([^\/-]+)\-([^\/-]+)\-([^\/-]+)\-([^\/-]+)$ ?p=$1+$2+$3+$4 [R=301,L]

You can take a look at how this work here:

thanks for your reply, please add exclude condition if url have slash at the end.
feligosky 8 months ago
I've forgot to account for the ?q= cases. I've added a new rule to deal with that
Titus 8 months ago (working fine. ) but if you test but slash and the end must be exclude from rewrite.
feligosky 8 months ago
You're right. I've used forward slashes instead of backwards slashes in the regex. I've updated the solution. I think this time it will work as expected.
Titus 8 months ago
Thanks, excelent!
feligosky 8 months ago
I'm glad I could help. Good luck.
Titus 8 months ago
View Timeline