Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Mod_Rewrite in HTTPD.CONF file

I want to rewrite URLs so when a user goes to;

http://www.example.com/applications/newWeb/www/index.php?page=48&thiscontent=2660&date=2013-10-11&pubType=0&PublishTime=09:30:00&from=home&tabOption=1

and if the URL contains thiscontent=2660 (which in this example above, it does) I want to redirect them to;

http://www.example.come/index.php/publications/finance-and-economics/departmental-resources

I have about 30 different thiscontent=XXXX types and imagine I’ll have to copy and edit this rule 30 different times for any links to my old website still knocking around out there.

I have access to my httpd.conf file but have never done a mod_rewrite before.

I also don't really need these showing up in the error logs as 301s. Will that happen? Because at the moment there are hundreds!

like image 614
mikelovelyuk Avatar asked Mar 22 '23 23:03

mikelovelyuk


1 Answers

First you need to make sure mod_rewrite is loaded. This line should be uncommented in your httpd.conf:

LoadModule rewrite_module modules/mod_rewrite.so

Then you can use these rules:

RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)thiscontent=2660(&|$)
RewriteRule ^/?applications/newWeb/www/index\.php$ http://www.example.come/index.php/publications/finance-and-economics/departmental-resources? [L,R=301]

And yeah, you'll need to setup each one specifically, so you'll need 30 of those (but only need RewriteEngine On once. You can also put these rules in an htaccess file in your document root.

like image 105
Jon Lin Avatar answered Apr 02 '23 20:04

Jon Lin