I’m trying to write a couple of rewrite rules for my drupal site in its .htaccess file and it doesn’t seem to work at all. My lack of prior knowledge and experience in regex and mod_rewrite doesn’t seem to help the cause either.
The URLs I’m trying to rewrite are as follows
Source:
http://www.mydrupalsite.com/somealphanumericwithspecialchars/somealphanumericwithspecialchars/somealphanumericwithspecialchars/somealphanumericwithspecialchars/Keyword1/Keyword2/UNIQUEID?queryparam1=somenumber
Destination:
http://www.mydrupalsite.com/legacystuff/UNIQUEID
My .htaccess mod_rewrite code is
RewriteEngine on
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
#This is the only rule written by me others are drupals
RewriteRule ^(.*)/(.*)/(.*)/(.*)/Keyword1/Keyword2/([0-9]*)?$ legacystuff/content/$5 [R=302]
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
My understanding and implementation based on some quick browsing on tutorials was the first four (.*) would match with the four alphanumericspecialchars in the URL, keyword1 and keyword2 would remain constant so i could match them as such, the unique numeric id which is actually required for my destination URL (param $5 in the destination) would be captured by ([0-9*])?. I use the following vhost in my httpd.conf of my local environment
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/mydrupalsite"
ServerName mydrupalsite.com
</VirtualHost>
My trouble is that the redirect from the source to destination URL does not occur after restarting my local server and clearing the cache. Any help on where I went wrong and how to make it right would be really appreciated.
Finally got it working, added the RewriteBase for my virtual host setting and placed my RewriteRule underneath it with the trailing ? in my destination to ignore query string and the L flag. Setting RewriteLog in my httpd.conf helped understand things from a better perspective. Hopefully this helps someone else new to .htaccess in drupal.