Forum Moderators: phranque
I've got a situation where I need to do a redirect in .htaccess including query strings. I've tried several things, but with no luck. In short, this is what I'm trying to accomplish:
http://www.example.com/gallery/index.php?pageId=0&start=0
needs to redirect to:
http://www.example.com/gallery/index.php?pageId=117&start=0
The only difference is the pageID=117 is changing, but different content gets populated into index.php based on pageId.
I tried this, but it doesn't do anything:
RewriteEngine On
RewriteRule ^gallery/index?pageId=0&start=0$ gallery/index.php?pageId=117&start=0
I'd love some help here, as I'm quite baffled.
Thanks,
Matt
Welcome to WebmasterWorld!
This recent thread [webmasterworld.com] should answer your question and help get you started.
Jim
Thank you for pointing me to that thread.
I've tried the following, but to no avail:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^pageId=([0-9]{3})$
RewriteRule ^index\.php$ http://www.example.com/gallery/index.php?pageId=%1&start=0 [R=301,L]
But it doesn't seem to be working (I'm very new to this). I changed the 2 to a 3 in the RewriteCond because three digits are needed for the new page (117), but I also don't see where in the above mod_rewrite, the 117 should be identified.
I then tried this, but still no luck:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^pageId=117$
RewriteRule ^index\.php?pageId=0&start=0$ http://www.example.com/gallery/index.php?pageId=%1&start=0 [R=301,L]
I also noticed, that the "&start=0" is not a vital part of the string, and can be eliminated from both URLS.
It's not clear what the interactions are between the two query parameters. For example, what if the "start=" value is not zero -- do you still want to do the rewrite in that case, or not? Does the "start=" value need to be passed to the new URL? Are there always two parameters, or could there be more or less? Are you expecting to rewrite multiple values of PageId, or just one? If more than one, how do the old PageIds map to the new ones?
Clearly, all we can do is point you in the right direction, as it would take you more time to type in *all* of the necessary details about your URL architecture than it would take to become very familiar with mod_rewrite.
For more information, see the documents cited in our forum charter [webmasterworld.com], especially the regular-expressions info, and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
index.php displays different content based on what the "pageId" is equal to. Whenever the the browser is pointed to:
http://www.example.com/gallery/index.php?pageId=0
I want it to automatically display the content from pageId=117. I figured the best (and maybe only way since I can't do a meta refresh in the code itself) is to do this with a mod_rewrite.
pageId=43, or pageId=68, or pageId=3, etc. all display unique content. The only instance I'm looking for is to have pageId=0 display (or redirect to) pageId=117. All others should stay the same.
As I appended to one of my previous posts, the &startId=0 can be removed from the equation entirely.
-Matt