0
votes

I am upgrading my site which involves new scripts and a different URL structure. There are currently a few thousand pages so I want to basically move them in to a subdirectory so that they are not lost.

I am not very confident with htaccess so can someone please confirm that the first part I have done is correct:

Old URL: http://www.example.com/article/another-dir/page-group/whatever.html

RewriteRule    ^article/?$    http://www.example.com/archive/    [R=301,NC,L]    

To achieve this: http://www.example.com/archive/another-dir/page-group/whatever.html

Search engines will see the above as a permanent move and in the address bar it will show the new url. Is this right?

The second part is on the new script - the url's could be improved but I am unable to change all the script so thought about using htaccess again but am not sure if it can be achieved like this.

At the moment the url looks like this: url: http://www.example.com/category/4/categoryname

In the htaccess the current rewrite rule for this type of url looks like this:

RewriteRule ^category/(.*)/(.*)$ category.php?id=$1&slug=$2

Is it possible to change this so that in the url address bar I end up with this: http://www.example.com/categoryname

Basically I don't want to see either the number or category/ in the resulting url as it will be easier for visitors to use - is that possible??

Thanks in advance for any help.

1

1 Answers

0
votes

The second question related to passing in URI components for querystring redirect and then hiding those components in the URL I don't think would be easy, if even possible, using RewriteRules.

For the first question though. Given the sample URLs you mentioned, the RewriteRule would need to include capture and backreference if you want to preserve the full URL in the redirection. For example:

RewriteRule ^article/?(.*)$ http://www.example.com/archive/$1 [R=301,NC,L]