Forum Moderators: phranque
I have a file in a directory structure that I want to redirect to another directory.
E.g /dir1/dir2/dir3/yyyymmdd/nnnn_yyyymmdd.shtml
y = year
m = month
d = day
n = number
I wanted to redirct it over to here
/newdir1/newdir2/newdir3/sameyyyymmdd/samennn_yyyymmdd.shtml
but my rewrite is causing a 500 error!
RewriteEngine on
RewriteRule ^([0-9]{8})/([0-9]{4})_([0-9]{8})\.shtml$ [domain.uk...]
Has anyone any ideas on how I can get around this.
Many thanks for any help offered.
m
To begin, there's a required space missing in front of [R,L].
A further possibility is that you also *may* need to add
Options +FollowSymLinks
ahead of your code. Do this only if you still get a 500 error after fixing the space, because sometimes this line is required, not needed, or not allowed, and it depends on your server config.
BTW, [R,L] is going to give you a temporary redirect. If this change is permanent, use [R=301,L].
Jim
I have a number of redirects in place on the live site which are similar or are performing virtually the same job. I am pretty confident FollowSymLinks is active.
I checked the .htaccess file and the space after the directed URL is also present. In the meantime I have tried a number of alternatives to the posted code, greedy and the like, but still have had no luck.
It seems to just get stuck in a loop.
You should've said so. I assumed that this code was *not* in the same path as both the old and new directories.
You'll need to add a RewriteCond to prevent redirection if the REQUEST_URI indicates a request for resources in the *new* directory structure -- Remember that after a 30x redirect, your .htaccess will be re-executed; if the new requested path still matches your redirect rule, then it will be re-redirected.
To stop this, put
RewriteCond %{REQUEST_URI} !^/newdir1/newdir2
ahead of your existing RewriteRule. You may have to adjust the pathnames to suit, depending on where you put this code.
Jim