Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

.htacceess mod rewrite

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

Dean

VIP Member
Impact
91
Just doing some mod rewrite stuff and am having a problem with the last bit, trying to get the URL created by the form get method to redirect to the type of URLs I want. Problem is I am getting 500 Internal server error.
Code:
RewriteRule ^random-integer/$ /integer.php
RewriteRule ^random-integer/number-([0-9]+)-minimum-([0-9]+)-maximum-([0-9]+)-unique-(yes|no).html$ /integer.php?num=$1&min=$2&max=$3&u=$4
RewriteRule ^random-integer/(.+)$ /random-integer/ [R=301]
RewriteRule ^random-integer$ /random-integer/ [R=301]

#Below code is causing problem
RewriteCond %{QUERY_STRING} ^?num=([0-9]+)&min=([0-9]+)&max=([0-9]+)&u=(yes|no)$
RewriteRule ^random-integer/$ /random-integer/number-%1-minimum-%2-maximum-%3-unique-%4.html [R=301]
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
on the last rule why are you using %1 %2 etc instead of $1, $2
 
0
Close
I thought you are meant to use %1 isntead of $1 for the query string values? Tryed it the other way to and it didnt work so dont think that is the problem.
 
0
Close
I think the first question mark in the RewriteCond line is wrong. The question mark is not part of the query string - it separates the query string from the rest of the URI. You probably want:

Code:
RewriteCond %{QUERY_STRING} ^num=([0-9]+)&min=([0-9]+)&max=([0-9]+)&u=(yes|no)$
You might want to consider adding some "L" flags to speed up rewrite rule processing.
 
0
Close
The ? was causing the error but I still couldn't get it to do what I actually wanted. I escaped & and = signs, not sure if this was needed, but what finally got it to work was putting it ahead of the other rewrite rules.

Just another question, I added [L] to the end of all the rewrite rules and there seems to be no problem but when should I use and not use this?
 
0
Close
Dean said:
Just another question, I added [L] to the end of all the rewrite rules and there seems to be no problem but when should I use and not use this?

The L flag makes mod_rewrite stop processing further rules. Use it if you don't want multiple rewrite rules to apply to the same URL.

Redirects cause a new URL to be requested, therefore the rules will be executed again.
 
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
CryptoExchange.com
Domain Recover

NamePros updates

Quick replies: search, your most used replies, and more on every post
Quick replies are easier to find and use now. The quick reply menu has a search box. Type a few letters to find the reply you want. A...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back