Forum Moderators: phranque

Message Too Old, No Replies

Redirect using variable in query string

         

davidonzo

8:37 pm on Jun 28, 2007 (gmt 0)

10+ Year Member



Great problem changing my bloggin platform.

My old permalinks are http://www.example.com/dblog/articolo.asp?articolo={ID}

Now I want to move to Apache using a PHP platform. My new permalink will be: http://www.example.com/post/{ID}/

I tried using RedirectMatch, but it doesn't work.

I tried using rewrite:

RewriteCond %{QUERY_STRING} ^articolo=(.*)$
RewriteRule ^/(.*)$ http://www.example.com/post/$1/ [R=301,L]

It doesn't work to...
What can I do?

Thanks in advance

davidonzo

1:09 pm on Jun 29, 2007 (gmt 0)

10+ Year Member



No solution to improve this redirect? :(

jdMorgan

6:19 pm on Jun 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is this code in the /dblog/.htaccess file?
Do you already have other working rules?

Your code is almost correct, but for use in .htaccess, the URL-path 'seen' by RewriteRule will not have a leading slash. So remove the leading slash from the RewriteRule pattern to start.

If you don't have any other working rules, then you will need to add

 RewriteEngine on 

ahead of your rule.

And if that still doesn't work, then add

 Options +FollowSymLinks 

ahead of the RewriteEngine directive. Note that this directive is either required or it is not needed and not allowed. The only way to find out is to test.

$1 refers the the value matched by the first RewriteRule pattern. %1 refers the value matched by the first RewriteCond pattern (of the last RewriteCond that matched if there are multiple RewriteConds).

You will also need to add a "?" to the substitution URL to clear the current query string.


Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{QUERY_STRING} ^articolo=(.*)$
RewriteRule ^articolo\.asp$ http://www.example.com/post/%1/? [R=301,L]

If this code is located in your main .htaccess file, then it will need to specify the /dblog/ path as well:

Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{QUERY_STRING} ^articolo=(.*)$
RewriteRule ^dblog/articolo\.asp$ http://www.example.com/post/%1/? [R=301,L]

Jim

davidonzo

8:29 pm on Jun 29, 2007 (gmt 0)

10+ Year Member



Thanks a lot Jim :)

The problem was the /dblog/ directory. In my new blog, all files will be stored in the root (or, in any case in a none dblog directory)

I solved creating the dblog directory and storing inside a different .htaccess
The code posted in the first post was part of the main .htaccess
Using this code

#############################
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^articolo=(.*)$
RewriteRule ^articolo\.asp$ http://example.com/post/%1/? [R=301,L]
###############################

In /dblog/.htaccess all works fine!

Thanks for the support and compliments for the board (since yesterday I was a great lurker ^_^ )