Hi guys,

I have this weird .htaccess rule that is used for a dropdown search engine

RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+) index.php?bla1=$1&bla2=$2... and so on [L]

If I want to maintain the above rule, it is allright.
The problem is that I want to creat a new rule with 3 variables, but the above rule is overwriting everything and it does not let me, what should I do?
If I rewrite the above rule, I will loose some important SEO ranking points.

Thanks in advance,
Szabi Zsoldos

Dani AI

Generated

Short diagnosis: mod_rewrite runs top->down, and a generic multi-segment rule will "steal" requests if it either appears before a more specific rule or is written too loosely. 's idea to use a dedicated prefix (like a /search/ path) is the safest approach because it cleanly separates the new URLs from the existing 4-segment URLs that needs to keep.

A practical, low-risk plan:

  • Keep the existing 4-segment URLs intact.
  • Add the 3-segment route with a distinctive prefix and place it before the generic rule.
  • Make patterns exact (use ^ and $ and allow an optional trailing slash), skip real files/dirs, and test rewrites with temporary redirects first.

Example (put this near the top of your rewrite block):

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# 3-segment search route (specific; place before the generic rule)
RewriteRule ^search/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?search=1&p1=$1&p2=$2&p3=$3 [L,QSA]

# Generic 4-segment rule but explicitly exclude the search prefix
RewriteRule ^(?!search/)([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?c1=$1&c2=$2&c3=$3&c4=$4 [L,QSA]

Notes and troubleshooting:

  • The negative lookahead (?!search/) prevents the 4-segment rule from matching search URLs; alternately use RewriteCond %{REQUEST_URI} !^/search/.
  • Use QSA to preserve query strings and test with R=302 before switching to permanent R=301.
  • To debug, enable rewrite trace logging (Apache 2.4+ LogLevel alert rewrite:trace3) or test specific URLs with curl -I to see which rule applies.
  • If you must change existing URLs, preserve SEO with 301 redirects, update sitemaps, and add canonical tags — but the prefix approach avoids that work and preserves rankings.

This keeps the old, SEO-critical 4-segment paths working while adding the new 3-parameter route safely.

Recommended Answers

All 2 Replies

Member Avatar for Member #120589

The only way I can think is...

RewriteRule ^search/([^/]*)/([^/]*)/([^/]*)/$ /?search=1&param1=$1&param2=$2&param3=$3 [L]

This forces the 'search' parameter. It does insist on 3 search parameters though - will not work on just 2 nor with 4

Example:

http://www.example.com/?search=1&param1=some&param2=thing&param3=else

Rewrite:

http://www.example.com/search/some/thing/else/

I'm not expert on this so not sure if this will work with your other rule.

Hello, this is what I should do, i know, I will loose some SEO ranking because of this :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.