Forum Moderators: phranque
how to
convert abc.com/page.htm?catid=2 or id number can range from 2 to 200 ( 3 digits )
to abc.com/id2.htm , id2.htm respectively.
I find rewritemap complicated, so if i had to code all the id numbers I don't mind to represent the static page output, but we can use regular expression to solve the numberical id problems right. Please help. thanks
rewriteRule abc\.com\/catid=([0-9]{1, 3})\.htm http:\/\/www\.abc\.com\/page\.htm\/?catid=$1 [L]
The bit in curly braces is where you change the numbers.
Regex tutorial
[etext.lib.virginia.edu...]
[edited by: ukgimp at 12:36 pm (utc) on Jan. 8, 2004]
Mod_rewrite will do what you need with one rewrite rule. I'm assuming you are doing this for search engine friendly URLs. If you changed all your URLs to point to /id101.htm, etc., the rule below will rewrite them into the original URL so your script will work perfectly and the URLs will appear static.
Hope it helps.
RewriteEngine on
rewriteRule ^id(.*)\.htm$ /page.htm?catid=$1 [L]
tried both of you guys recommendations but cant do
here's my code
RewriteEngine On
RewriteRule ^\CatId=([0-9])\.htm$ /page\.htm/?CatId=$1 [L]
no error what so ever.. I tried other .htaccess file for redirecting of user & it works perfectly..?
If so, you'll need to use RewriteCond %{QUERY_STRING} <pattern> to access the query-string; mod_rewrite does not consider the query string in RewriteRules.
It is more usual to have your script output friendly (static) URLs to browsers and search engines, and then convert those static URLs back into queries to your script. Mod-rewrite acts after a request is received, but before your script is called. mod_rewrite has no effect after your script is called.
Therefore, it's important to know which way you actually want the conversion to work.
Jim
while Querystring method which
RewriteCond %{query_string} ^$
RewriteRule ^page\.htm?categoryid=(3)$
Tried some of php scripts online to to convert from static to php but to no avail too.
<?
function processURI() {
global $REQUEST_URI;
$array = explode("'(?<!/)page.htm\?CategoryId=3'",$REQUEST_URI);
$num = count($array);
$url_array = array(subpage3.htm);
for ($i = 1 ; $i < $num ; $i++)
$url_array["arg".$i] = $array[$i];
return $url_array;
function displayContent($array)
section = $array["arg3"];
$cat = $array["arg4"];
$content = "content/"
. $section
. "_"
. $cat
. ".htm";
if (!file_exists($content))
content = "error.php";
include($content);
} else {
include($content);
}
}
?>
<?
$myarray = processURI();
?>
So any hints? clues, pls pretty pls...
how to convert example.com/page.htm?catid=2 or id number can range from 2 to 200 (3 digits) to example.com/id2.htm , id2.htm respectively.
Internal redirects:
RewriteCond %{QUERY_STRING} ^catid=([0-9]{1,3})$
RewriteRule ^page\.htm$ /id%1.htm [L]
RewriteRule ^id([0-9]{1,3})\.htm$ /page.htm?catid=$1 [L]
External redirects:
RewriteCond %{QUERY_STRING} ^catid=([0-9]{1,3})$
RewriteRule ^page\.htm$ http://example.com/id%1.htm [R=301,L]
RewriteRule ^id([0-9]{1,3})\.htm$ http://www.example.com/page.htm?catid=$1 [R=301,L]
The above code allows id numbers of 0 to 999. If constraining the id numbers to range between 2 and 200 (inclusive) and requiring the non-leading-zero format is important, then replace all occurrances of
"([0-9]{1,3})"
- with -
"([2-9]¦[1-9][0-9]¦1[0-9]{2}¦200)".
Change all broken pipe characters "¦" to solid pipe characters (usually SHIFT \ on keyboard) before use.
The above code is intended for use in an .htaccess context. If you wish to use it in httpd.conf, then you will have to add a leading slash to the pattern in each RewriteRule, e.g.
RewriteRule [b]^/p[/b]age\.htm$ /id%1.htm [L] Jim
Internal:
RewriteCond %{QUERY_STRING} ^catid=([0-9]{1,3})$
RewriteRule ^page\.htm$ /id%1.ht[b]m?[/b] [L]
RewriteCond %{QUERY_STRING} ^catid=([0-9]{1,3})$
RewriteRule ^page\.htm$ http://example.com/id%1.ht[b]m?[/b] [R=301,L]
[L] means that no more rewrite rules need to be processed for this request - it is the usual default.
[R], [R=301], or [R=302] is an external redirect, and you must specify a full URL, like "http://www.example.com/file.pl"
If there is no [R], then you must specify a local path only, like "/file.pl"
Use the flags [R] and [L] exactly as shown above for maximum happiness. ;)
If you want the new URL to show in your browser, then use an external redirect, [R=301,L]. If not, then use an internal rewrite only [L].
A server response code of 304 means that the requested page contents have not been changed since last requested, and so it was not loaded from your server, it was loaded from your browser or ISP cache -- flush your cache before testing!
Jim