SEO URLs with ColdFusion Controller?

quick ref: area = portal page.

I would like the old URLs http://domain.com/long/rubbish/url/blah/blah/index.cfm?id=12345 to redirect to http://domain.com/area/12345-short-title

http://domain.com/area/12345-short-title should display content.

I have developed so far to do this, I could use apache to write all the URLs in

http://domain.com/ index.cfm /long/rubbish/url/blah/blah/index.cfm? ID = 12345 and also http://domain.com/ index.cfm / area / 12345-short-title

index.cfm will either download the content or apply a permanent redirect, but first it needs to get information about the name and area from the database.

This site has 50,000 pages. I also have other ideas for redirecting subdomains and persistent subdomains and managing their actions through index.cfm.

The infrastructure is interested in rewriting Apache as much as possible, we suspect that it will be faster. However, I am not sure that we have such a choice if we need to get information about the zone and names for each page.

Does anyone have experience with this that can provide input?

-

Something note, I assume that we will have to store all the internal URLs used on the website in the old format. It would be a great job to change them.

This means that all internal URLs will need to use constant redirects every time.

+4
source share
2 answers

Instead of redirecting both groups of URLs to the same script, why not just send them to two different scripts?

Just:

RewriteCond ${REQUEST_URI} !-f RewriteRule ^\w+/\d+-[\w-]+$ /content.cfm/$0 [L] RewriteCond ${REQUEST_URI} !-f RewriteRule ^.* /redirect.cfm/$0 [L,QSA] 

Then redirect.cfm can search for the replacement URL and redirect 301, while content.cfm just serves the content.

(You did not specify how your CF is configured, you may need to update the Jrun / Tomcat / other configuration to support /content.cfm/* and /redirect.cfm/* - this will be done in the same way as for index.cfm)


For performance reasons, you still want to avoid getting into the database for redirection if you can, and you can do this by creating rewrite rules for each page that performs 301 redirects on the Apache side. It can be as simple as adding a line to the .htaccess file, for example:

 <cfset NewLine = 'RewriteRule #ReEscape(OldUrl)# #NewUrl# [L,QSA,R=301]' /> <cffile action="append" file="./.htaccess" output=#NewLine# /> 

(where OldUrl and NewUrl were scanned from the database.)

You can also research using mod_alias redirect instead of mod_rewrite RewriteRule, where the syntax is Redirect permanent #OldUrl# #NewUrl# - since OldUrl is the exact path it matches, it will probably be faster.

Please note that these rules must be checked before the redirect.cfm is redirected - if they are in the same .htaccess, you cannot just add append, but if they are in the general Apache configuration files then first .htaccess rules will be checked.

Also, according to Sharon's comment, you should check if your Apache will handle 50k rules while I saw that it said that โ€œthousandsโ€ of Apache rewritable rewritable regex works fine, there might be some limit (or at least you need to split into several files).

+3
source

Using apache rewrites would only be faster if they were static rewrites, or if they all followed some rule that you could write in regex in a .htaccess file. If you need to touch the database for these redirects, then it may not make sense to do this in .htaccess.

Another approach is the one used by most CMS to handle virtual directories and redirects. The index.cfm file in the root of the site processes all incoming requests and returns the correct pages and path. MURA CMS takes this approach (as well as Joomla and most others).

Basically, you use the CGI.path_info variable for an incoming request, look for it in your database and redirect to a new path. As usual, Ben Nadel is well versed in how to use this approach: Ben Nadel: using the rewrite of IIS and CGI.PATH_INFO URLs using IIS MOD-Rewrite

However, you can use .htaccess to remove "index.cfm" from the entire url string if you want, redirecting all incoming requests to the root URL with something that looks like this in your .htaccess:

 RewriteEngine On RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d RewriteRule ^([a-zA-Z0-9-]{1,})/([a-zA-Z0-9/-]+)$ /$1/index.cfm/$2 [PT] 

This basically redirects something like http://www.yourdomain.com/your-new-url/ to http://www.yourdomain.com/index.cfm/your-new-url/ where it can be processed, as described above on the blog. The user will never see index.cfm.

0
source

Source: https://habr.com/ru/post/1439159/


All Articles