Forum Moderators: phranque
http://www.example.com/index.php?option=com_content&task=view&id=132&Itemid=2&Itemid=2
to
http://www.example.com/132
where the post number is the id value in the first address and can be from 1 to 5 digits.
In my .htaccess file I tried, with no luck, the following:
RewriteEngine On
RewriteBase /
RewriteRule &id=(\d{1,5}) /$1 [R=301,NC]
RewriteRule ^(\d{1,5})/?$ /?p=$1 [NC,L]
Can you help me? I am not able to find the error.
Thanks a lot.
Use a RewriteCond to examine %{QUERY_STRING}, as in:
RewriteCond %{QUERY_STRING} ^([^&]*&)*id=([0-9]{1,5})(&.*)?$
RewriteRule ^(index\.php)?$ /?p=%2 [NC,L]
Jim
RewriteCond %{QUERY_STRING} ^([^&]*&)*id=([0-9]{1,5})(&.*)?$
RewriteRule ^(index\.php)?$ /?p=%2 [NC,L]1 - ([^&]*&)* = zero or more groups of characters that are not "&" followed by a "&" (btw, wonderful!)?
2 - Is the use of "%" better then "$"?
About my code, since WP posts are written like "/?p=#*$!x" where #*$!x is the id post number,
I added the second rule:
RewriteRule ^(\d{1,5})/?$ /?p=$1 [NC,L]
to overwrite what I was trying to rewrite (i.e. /?queryString&id=nnnn$anotherQuery to /nnnn and then to /?p=nnnn) to make it simpler for visitors to remember it.
Anyway, thanks a lot.
Is there a simple reference to study for that RewriteCond?
[edited by: jdMorgan at 2:48 am (utc) on Jan. 9, 2010]
[edit reason] Disabled smilies in post. [/edit]