Complete URL to Another Complete URL

New to mod_rewrite? This is a good place to start.

Complete URL to Another Complete URL

Postby SemperFiWS » Wed Aug 05, 2009 2:59 pm

Quick question...

Is it possible to redirect this:
http://www.example.com/test/index.php?a ... umentId=10
to:
http://www.example.com/test/index.php?a ... stListings

This needs to happen when :
- the first URL is type in directly
- is clicked on via a link
- accessed via search engines

The second link is what needs to be in the address bar.
The redirect needs to be 301.

Any help on this would be much appreciated.
SemperFiWS
 
Posts: 4
Joined: Wed Aug 05, 2009 2:53 pm

Postby richardk » Wed Aug 05, 2009 3:46 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?act=Document(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?documentId=10(&.*)?$ [NC]
RewriteRule ^test/index\.php$ /test/index.php?act=viewTestListings [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby SemperFiWS » Wed Aug 05, 2009 4:04 pm

Thanks for the prompt response, very much appreciated.

Unfortunately, that didn't work.
The same page content remained and the URL stayed as the original.
SemperFiWS
 
Posts: 4
Joined: Wed Aug 05, 2009 2:53 pm

Postby richardk » Wed Aug 05, 2009 5:12 pm

Did you put it in /test/.htaccess? If you did, replace
Code: Select all
^test/index\.php$

with
Code: Select all
^index\.php$

(or
Code: Select all
^(index\.php)?$

if you want it to match /test/?act=Document&documentId=10 as well).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby SemperFiWS » Wed Aug 05, 2009 5:23 pm

I tested it in the root directory.

For now, I have just taken care of it using PHP when that specific document is requested.

Do you see any problem with using that method?
SemperFiWS
 
Posts: 4
Joined: Wed Aug 05, 2009 2:53 pm

Postby richardk » Fri Aug 07, 2009 1:40 pm

I'd probably have done it with PHP, too. As long as you have written good PHP code it shouldn't be a problem.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby SemperFiWS » Fri Aug 07, 2009 1:48 pm

Great to hear.
Again, thanks for your help :)
SemperFiWS
 
Posts: 4
Joined: Wed Aug 05, 2009 2:53 pm


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 27 guests

cron