Search code examples
.htaccessmod-rewriteurl-rewritingisapi-rewrite

redirecting technical links to SEO links


I have a map file which is working fine with SEO-friendly URLs

Now the customer want that the user should not be allowed to access the technical links means only SEO links should be accessable

e.g my map file looks like

buche-massiv-weiss-lackiert.html /?page=datail&productid=1212

at the moment SEO is working, but what I need is that If the user calls this technical link i.e

/?page=datail&productid=1212

if should also be first redirected to SEO link and then the page should be called.

what will be the best way to do so?


Solution

  • In the same mapping file add a reverse entries like this:

    /?page=datail&productid=1212 buche-massiv-weiss-lackiert.html
    

    Then have this rule at top of your htaccess for redirection to pretty URL:

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/*(/.*?)\sHTTP [NC]
    RewriteCond %1::${mymap:%1} ^(.*)::.
    RewriteRule .* ${mymap:%1}? [L,NE,R=301]
    

    This is assuming name of your RewriteMap is mymap. Change it to whatever your map name is.