Forum Moderators: phranque
I know this questions may have been asked many time on the forum and everywhere and also got answered, but do not seem to be able to find a working solution to match my needs.
I have a lot of pages on my website which use query strings and would like to redirect them to show meaningful URLS, such as:
user types: www.domain.com/article/15/?page=12
should redirect to: www.domain.com/article/15/12/
user types: www.domain.com/something/2/?page=21
should redirect to: www.domain.com/something/2/21/
user types: www.domain.com/another/33/22/?page=50
should redirect to: www.domain.com/another/33/22/50/
So, in a way and general expression that would handle any query string containing the word "page=" and if it is something else it should not do anything, because I have some ajax calls to some files which use query strings and I do not want those to stop working.
Also, would it be okay to have internat links on the webpages I am generating to have hyperlinks same as the ones I marked above as "user types", or should I change them to be like the redirected ones? Actually I was wondering if it is going to slow the website down or something?changing them might not be a big problem, but I just thought if things can be fine without me changing those links of each files.
I was also getting a little confused on the idea of redirect. Actually if the above starts working for the users and the query string are adjusted to make the url look better. What will happen if the user enters the nicely formed URL, so:
instead of: www.domain.com/another/33/22/?page=50
user types this: www.domain.com/another/33/22/50/
will the user be able to see the pages fine? Its like thinking upside down, hope this makes sense!
Please help me out I am very confused.
Jim
user types: www.domain.com/article/15/?page=12
should redirect to: www.domain.com/article/15/12/
user types: www.domain.com/something/2/?page=21
should redirect to: www.domain.com/something/2/21/
user types: www.domain.com/another/33/22/?page=50
should redirect to: www.domain.com/another/33/22/50/
But the example only shows example for redirects in the corrent folder. I tried doing this:
Options +FollowSymlinks
RewriteCond %{QUERY_STRING} page=(.+)
RewriteRule (.*)index\.php [domain.com...] [R=301,L]
but this did not seem to work either, it was even redirecting [domain.com...] to [domain.com...]
which was wrong and also I could not get rid of the "?page=12", another thing was that it did not worked on an example that used "\?page=12" without an index.php file in front of it.
Could you please help?
Options +FollowSymlinks
RewriteEngine on
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)+\?page=([^&]+)&?[^\ ]*\ HTTP/
RewriteRule ^(([^/]+/)+)$ http://www.example.com/$1%2? [R=301,L]
[edited by: jdMorgan at 3:36 pm (utc) on Aug. 5, 2008]
$page = $_GET["page"];
I wonder if this previously supplied rules change the way I catch the query argument, because at the moment I am getting 404 not found error, but the url formation is fine.
would the above supplied rules provide rules work if the user types in the nicely formatted URL at the first place? I mean if the user types in www.domain.com/another/33/22/50/ will he/she get the correct page because in the background my php file should be invoked like this should redirect to: www.domain.com/another/33/22/?page=50 to generate that page.
If you have specific questions not already answered in that thread, please post them here.
Jim