Redirecting millions of URL from /forum to /forums - url-rewriting

I had a forum with /forum but it has changed to /forums
I want to know if there is a single line code which can redirect my old URL to new ones.
It is not simple redirection from /forum to /forums
The URL after /forum/abc.html are now /forums/abc.html
There are some 500000 URL that need to be changed. Could anybody help?
For example:
example.org/forum/topic/144934-pio-threatened-rti-applicant/ is now example.org/forum**s**/topic/144934-pio-threatened-rti-applicant/
If you see above the change is just 'S' for all the 500000 URLs
I have already tried this:
RewriteEngine On
RewriteRule ^forum/(.*)$ /forums/$1 [NC,L]

Related

mod_rewrite - replace word or character in url

Am trying to mod_rewrite a URL, but unfortunately without any luck.
http://mywebsite.com/gallery/mycustom-gallery/linkid417
Should be changed to:
http://mywebsite.com/gallery/mycustom-gallery/#417
Where '417' is a dynamic id of an image & mycustom-gallery will also change every-time.
I've tried the following rules, but none seems to work...
RewriteRule ^/gallery/$1/#([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/y/([0-9]+)$ /gallery/$1/linkid [L,R=301]
RewriteRule mycustom-gallery/#.*$ /mycustom-gallery/linkid=417/$1
Regards,
Charl
If you are trying to rewrite from http://mywebsite.com/gallery/mycustom-gallery/linkid417 to http://mywebsite.com/gallery/mycustom-gallery/#417 you can do it as follows:
RewriteRule ^/gallery/([a-zA-Z0-9_-]+)/linkid([0-9]+)$ /gallery/$1/#$2 [NE,L,R=301]
The NE|noescape flag prevents Apache from escaping the hash in the URL during the 301 redirect.
If however you wish to do the opposite, i.e. redirect from http://mywebsite.com/gallery/mycustom-gallery/#417 to http://mywebsite.com/gallery/mycustom-gallery/linkid417, that cannot be done, as the fragment part of the request ("#417") is not passed to Apache along with the request as per RFC1808.

Redirect an URL with all variables to another URL

I need to redirect a URL to another URL. So far I have done this in the .htaccess:
Redirect 301 http://domain.com/mypage.php http://newdomain.com/mynewpage
This works fine, but it copies the GET variables in the new URL as well. So I end up with
http://domain.com/mypage.php?item=32
being redirected to:
http://newdomain.com/mynewpage?item=32
I want remove all the variables in the new ULR. I know that this has to be done somehow with mod_rewrite, but I am struggling a lot with it and can not make it work.
Any help is appreciated.
Thanks
Ok,I got it myself... here is what I have done:
RewriteEngine On
RewriteCond %{QUERY_STRING} (.*)
RewriteRule (.*) %{REQUEST_URI}?

mod_rewrite from a subfolder with a querystring to a folder or file

I am trying to redirect from:
http://www.example.com/folder/product.aspx?prodid=146
to
http://www.example.com/folder2/folder3/
The folders referred to here don't really exist. There are other rewrite rules in place which redirect transparently to the actual content.
If I create a directory called 'folder', and put an .htaccess file in it, I can get the redirect working, BUT, other URLs which refer to that folder no longer work. So I have to try and do the redirect from the .htaccess file in the ROOT folder.
I tried this:
RewriteCond %{QUERY_STRING} prodid=146
RewriteRule ^/folder/product.aspx$ /folder2/folder3/? [R]
...but it doesn't work (I get a 404 error). Using identical syntax but omitting the /folder/ from the 2nd line works if the .htaccess is in the folder directory (so I know the above can't be too far off) - but as I said, I cannot do that. I have tried lots of variations but nothing seems to work. Any assistance appreciated.
You need to remove the slash from the start your URL regexp. Like this:
RewriteRule ^folder/product.aspx$ /folder2/folder3/? [R]

Redirecting */test/* in httpd.conf to */* [Removing /test/ in path]

we've been running a test verions of our site at www.mystie.com/test/ and these urls are being used by everyday people... how can i configure httpd.conf to now redirect all these old urls to the / location?
ie,
www.mysite.com/test/image1.jpg
should be:
www.mysite.com/image1.jpg
There are other httpd conf rules in there, so i assume i 'll have to place this up front
Just add these lines:
RewriteEngine on
RewriteBase /
RewriteRule ^test/(.*)$ /$1 [R=301,NC,L]
If lines 1 and 2 have already been set, then you can omit those.
If you prefer, you can add this into your .htaccess file in the root web directory instead. Slightly slower, but saves restarting httpd.
I guess you would need a 301 redirect (which should help in SEO as well)
Redirect 301 /test/ /
Looks like #melkamo has the .htaccess covered.
The alias_module will allow you to do it in httpd.conf
`Redirect permanent /test http://localhost`
It will erase test from the URL if it is the first subdirectory

form post to mod_rewrite url

I am trying to submit a form to the url "localhost/login". Inside my login directory I have an index.php file with the code I am using to debug that the post is working:
<?php
echo $_POST['username'];
?>
I have a .htaccess file inside my login directory:
RewriteEngine on
RewriteRule ^. index.php [L]
The problem is, when I post to localhost/login my firebug shows that the initial POST goes through, but then redirects to login.php as a GET request without any POST variables...
POST
http://localhost/login?password=test_password&remember=true&username=test_username
301 Moved Permanently
GET
http://localhost/login/
200 OK
Any tips would be great.
Thanks
I have a condition in my .htaccess file:
RewriteBase /
RewriteCond %{HTTP_HOST} !^www(.*)
RewriteRule ^(.*) http://www.%{HTTP_HOST}%{REQUEST_URI}
which rewrites any links without the prefix "www". Like this:
http://mysite.com to http://**www**.mysite.com
And that was the problem I had:
in my form I have forgotten to put the "www" and so my POST array was empty.
Putting the www in the form like this:
action="http://www.mysite.com/login"
instead of:
action="http://mysite.com/login"
fixed the problem for me.
Based on my research, POST should be allowed to be rewritten and come out as POST, any sort of problem is probably due to something else going wrong, like your code.
Btw, in general, to keep the GET parameters from being stripped, use the QSA directive:
[QSA,L]

Resources