(seo|rewrite)rules and databases

Helicon Ape provides support for Apache .htacces and .htpasswd configuration files for Microsoft IIS.
User avatar
Posts: 14
Joined: 11 Jun 2014, 10:50

(seo|rewrite)rules and databases

13 Oct 2014, 07:05

Hi to all!

I want to rewrite urls with a backend database.
To do that, i've created a table called SEO_URL_REWRITE with 2 column named ORIGINAL_URL and SEO_URL.

My goal is to call SEO_URL record with ORIGINAL_URL key with SeoCond/SeoRule syntax, and do the reverse call ORIGINAL_URL record with SEO_URL key with RewriteCond/RewriteRule syntax, because i want to show same pages with different urls (for example, original page like www.mydomain.com/WHO_ARE_US.asp and URL like www.mydomain.com/who-are-us.html).

To do this, I've used an example you made in the mod_rewrite page, so i wrote:

RewriteEngine On
SetEnv mod_seo
RewriteBase /

DBDriver mssql
DBDParams "*Correct parameters to connect db*"

DBDPrepareSQL "select SEO_URL from SEO_URL_REWRITE where Original_URL=@KEY" getSEO
DBDPrepareSQL "select Original_URL from SEO_URL_REWRITE where SEO_URL=@KEY" getOriginal

RewriteMap dest01 dbd:getSEO
RewriteMap dest02 dbd:getOriginal

SeoCond ${dest01:$1|NOT_FOUND} (.*)
SeoCond %1 !NOT_FOUND
SeoRule (.+) %1 [Redirect, Scope=ALL]

RewriteCond ${dest02:$1|NOT_FOUND} (.*)
RewriteCond %1 !NOT_FOUND
RewriteRule (.+) %1 [L]

The seoCond/seoRule instructions work correctly, but not the RewriteCond/RewriteRule instructions, in fact the server returns 404 page. There's a syntax or run-time error? Thanks a lot for your help!

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: (seo|rewrite)rules and databases

13 Oct 2014, 07:22

Hello,

There are no obvious mistakes I can see, so it would be helpful to see rewrite.log records which you will gt in Ape install folder after you put

RewriteLogLevel 9

in httpd.conf file.

Also, please show several lines from both of your mapfiles to make sure they are correct.

User avatar
Posts: 14
Joined: 11 Jun 2014, 10:50

Re: (seo|rewrite)rules and databases

13 Oct 2014, 10:19

Here it is rewrite.log file.

The mapfiles dest01 and dest02 are strangely empty...

in mapfile.txt there are written:
http://mydomain.it/ITA/Home.asp http://mydomain.it/ITA/Home.html

in revmapfile.txt there are written:
http://mydomain.it/ITA/Home.html http://mydomain.it/ITA/Home.asp
Attachments
rewrite.log
(5.39 KiB) Downloaded 1541 times

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: (seo|rewrite)rules and databases

13 Oct 2014, 10:40

Hello,

How can it be that "The seoCond/seoRule instructions work correctly" if the mapfiles are empty?

Can you also try to simplify your rules like this:

SeoCond ${dest01:$1|NOT_FOUND} !NOT_FOUND
SeoRule (.+) ${dest01:$1} [Redirect, Scope=ALL]

RewriteCond ${dest02:$1|NOT_FOUND} !NOT_FOUND
RewriteRule (.+) ${dest02:$1} [L]

User avatar
Posts: 14
Joined: 11 Jun 2014, 10:50

Re: (seo|rewrite)rules and databases

13 Oct 2014, 11:19

I've tried to insert these 2 strings:

http://mydomain.it/ITA/Home.asp http://mydomain.it/ITA/Home.html in dest01

http://mydomain.it/ITA/Home.html http://mydomain.it/ITA/Home.asp in dest02

but nothing changed.

I don't know why seo(cond|rule) part works correctly with dest01 and dest02 empty, I usually work with seo/rewrite rules and databases using specified rules for any page, but I want to write one rule for all my sites. For example I have a site with 33 mapfiles (named dest01, dest02 and so on) and it works correctly without any destXX file in the path. It's very strange!

Unfortunately the suggest you wrote (seo/rewrite) part doesn't work (same 404 error). Any other ideas? Thank you very much!

User avatar
Posts: 14
Joined: 11 Jun 2014, 10:50

Re: (seo|rewrite)rules and databases

14 Oct 2014, 06:37

Solved!

I've wrote

SeoCond ${dest01:$1|NOT_FOUND} !NOT_FOUND
SeoRule (.+) /${dest01:$1} [Redirect]

RewriteCond ${dest02:$1|NOT_FOUND} !NOT_FOUND
RewriteRule (.+) ${dest02:$1}

In db, SEO_URL record don't want to have first /, for example

ITA/Home.html instead of /ITA/Home.html

because (in my opinion) Substitution part of rules must have at least one fixed character.

Return to Helicon Ape

Who is online

Users browsing this forum: No registered users and 30 guests