index.php?a to index.php?b

Oh, the strange things mod_rewrite does!

index.php?a to index.php?b

Postby markc » Wed Jan 10, 2007 11:32 pm

I'm trying to rewrite index.php?page=something to index.php?title=something but this rule gives the listed result below. Anyone have a clue how to do something as simple as this ?
Code: Select all
  RewriteCond %{QUERY_STRING} ^page=([^&]+)$
  RewriteRule index.php index.php?title=%1 [L]

Result:
... rewrite index.php -> index.php?title=something
... initial URL equal rewritten URL: /www/index.php [IGNORING REWRITE]
markc
 
Posts: 2
Joined: Wed Jan 10, 2007 11:23 pm

Postby richardk » Fri Jan 12, 2007 10:38 am

Is ./index.php?title=* in the address bar of your browser? Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^title=([^&]+)$
RewriteRule ^index\.php$ ./index.php?page=%1 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

That worked, thanks

Postby markc » Fri Jan 12, 2007 3:41 pm

It was needed to convert an incoming page=* to a title=*. Your suggestion works and is almost what I had but with a (^index\. and a ./index) few dots and slashes added. The R=301 forces the resulting URL in the location bar to change to the new title=* version. Thanks again for your help.
Code: Select all
#  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{QUERY_STRING} ^page=([^&]+)$
  RewriteRule ^index\.php ./index.php?title=%1 [R=301,L]
markc
 
Posts: 2
Joined: Wed Jan 10, 2007 11:23 pm


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 5 guests

cron