Welcome Guest, Not a member yet? Register   Sign In
The best way to re-route old urls
#1

[eluser]dobbler[/eluser]
Hi,

Can anyone tell me which is the best method of re-routing old urls to the corresponding CI url?

In routes, I've tried this but to no avail:

Code:
$route['eventsi.asp?e=(:num)'] = 'events/e/$1';

Should I be using htaccess and if so, how?

Thanks in advance!

Rob.
#2

[eluser]michalsn[/eluser]
Yes, htaccess is the best solution here.
Code:
RewriteEngine on
RewriteRule ^eventsi.asp?e=([0-9]+)$ /events/e/$1 [R=301,L]
#3

[eluser]dobbler[/eluser]
@michalsn Thanks for your speedy reply!

However, that does not seem to be working, here is my full htaccess code, maybe I'm doing something wrong?

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|images|css|temp|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
RewriteCond %{QUERY_STRING} ^frob=(.*)&extra;=(.*)$ [NC]
RewriteRule ^.*$ /gallery/callback/%1/? [R=301,L]
RewriteRule ^eventsi.asp?e=([0-9]+)$ /events/e/$1 [R=301,L]

<IfModule mod_security.c>
  # Turn off mod_security filtering.
  SecFilterEngine Off

  # The below probably isn't needed,
  # but better safe than sorry.
  SecFilterScanPOST Off
</IfModule>

<IfModule mod_security.c>
  SetEnvIfNoCase Content-Type \
  "^multipart/form-data;" "MODSEC_NOPOSTBUFFERING=Do not buffer file uploads"
</IfModule>

<IfModule mod_gzip.c>
  mod_gzip_on No
</IfModule>
#4

[eluser]mdvaldosta[/eluser]
Put the old urls to rewrite first, otherwise you're letting CI get to them and serve a 404 before you have a chance to rewrite them.
#5

[eluser]michalsn[/eluser]
@dobbler you're right - this should work ok:
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|eventsi\.asp|resources|images|css|temp|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
RewriteCond %{QUERY_STRING} ^frob=(.*)&extra;=(.*)$ [NC]
RewriteRule ^.*$ /gallery/callback/%1/? [R=301,L]
RewriteCond %{QUERY_STRING} ^e=([0-9]+)$
RewriteRule ^eventsi\.asp$ /events/e/%1? [R=301,L]

<IfModule mod_security.c>
  # Turn off mod_security filtering.
  SecFilterEngine Off

  # The below probably isn't needed,
  # but better safe than sorry.
  SecFilterScanPOST Off
</IfModule>

<IfModule mod_security.c>
  SetEnvIfNoCase Content-Type \
  "^multipart/form-data;" "MODSEC_NOPOSTBUFFERING=Do not buffer file uploads"
</IfModule>

<IfModule mod_gzip.c>
  mod_gzip_on No
</IfModule>
#6

[eluser]dobbler[/eluser]
[quote author="michalsn" date="1304033893"]@dobbler you're right - this should work ok:
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|eventsi\.asp|resources|images|css|temp|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
RewriteCond %{QUERY_STRING} ^frob=(.*)&extra;=(.*)$ [NC]
RewriteRule ^.*$ /gallery/callback/%1/? [R=301,L]
RewriteCond %{QUERY_STRING} ^e=([0-9]+)$
RewriteRule ^eventsi\.asp$ /events/e/%1? [R=301,L]

<IfModule mod_security.c>
  # Turn off mod_security filtering.
  SecFilterEngine Off

  # The below probably isn't needed,
  # but better safe than sorry.
  SecFilterScanPOST Off
</IfModule>

<IfModule mod_security.c>
  SetEnvIfNoCase Content-Type \
  "^multipart/form-data;" "MODSEC_NOPOSTBUFFERING=Do not buffer file uploads"
</IfModule>

<IfModule mod_gzip.c>
  mod_gzip_on No
</IfModule>
[/quote]

Yes that works but when I put in "^eventsi\.asp?e=([0-9]+)$" it gives me the disallowed url error again.

I've also tried escaping with "RewriteRule ^eventsi\.asp\?e\=([0-9]+)$ /events/e/$1 [R=301,L]"

I also added in events\.asp into the RewriteCond:

Code:
RewriteCond $1 !^(index\.php|eventsi\.asp|resources|images|css|temp|js|robots\.txt|favicon\.ico|mailer)

I just can't seem to get my head around htaccess!

Thanks for your help so far!

Rob.
#7

[eluser]dobbler[/eluser]
Ok, thanks. I almost have it working..

It works perfectly on the live server so essentially, it's working fine.. However, on my local server it's redirecting a folder back

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|eventsi\.asp|resources|images|css|temp|js|robots\.txt|favicon\.ico|mailer)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
RewriteCond %{QUERY_STRING} ^frob=(.*)&extra;=(.*)$ [NC]
RewriteRule ^.*$ /gallery/callback/%1/? [R=301,L]
RewriteCond %{QUERY_STRING} e=(.*) [NC]
RewriteRule ^eventsi\.asp$ /events/e/%1? [R,L]

This works on the live server but locally I get this:
When I hit: "http://www.mydomain.com/secc/eventsi.asp?e=879" (domain on local server Users/me/Sites/secc MAMP)

I get redirected to this: "http://www.mydomain.com/events/e/879"

Which is obviously missing the "secc" which is the folder I'm developing in.

Any ideas on why this is happening and/or how to fix it?

Thanks again for your help so far.

Rob.
#8

[eluser]michalsn[/eluser]
Try add secc folder to rewrite rule:
Code:
RewriteRule ^eventsi\.asp$ /secc/events/e/%1? [R,L]




Theme © iAndrew 2016 - Forum software by © MyBB