4

I have a path like this

http://host.ip/nl/producten-en-diensten/abonnementen-met-gsm

which will retrieve the correct content and I also want to receive the same content when I access the below URL also

http://host.ip/nl/business/producten-en-diensten/abonnementen-met-gsm

Note:

  • host.ip/nl/ - Static
  • producten-en-diensten/abonnementen-met-gsm - Dynamic, it will change
  • /business keyword will append next to nl

I have referred to the rule given in this post: How can I create a shorter alias URL to a longer URL using an .htaccess file?

but no success

@Magento URL rewrite management will do exactly this, but I am trying to achieve this using .htaccess.

I have tried like this but it is redirecting

RewriteRule (^|.*?/)nl/business/(.*)$ /$1nl/$2 [R=302,L,NC]

Here is my rewrite tag in .htaccess

<IfModule mod_rewrite.c>

############################################
## Enable rewrites

    Options +FollowSymLinks
    RewriteEngine on

## Business Rewrite
    RewriteRule (^|.*?/)nl/business/(.*)$ /$1nl/$2 [NC]

############################################
## You can put here your magento root folder
## path relative to web root

    #RewriteBase /magento/

############################################
## Workaround for HTTP authorization
## in CGI environment

    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

############################################
## TRACE and TRACK HTTP methods disabled to prevent XSS attacks

    RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
    RewriteRule .* - [L,R=405]

############################################
## Never rewrite for existing files, directories and links

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l

############################################
## Rewrite everything else to index.php

    RewriteRule .* index.php [L]

</IfModule>
0

1 Answer 1

1

Just remove the R=302, from your rule. R means "redirect" and 302 means "temporary type":

RewriteRule (^|.*?/)nl/business/(.*)$ /$1nl/$2 [L,NC]

For further info about your rule:

  • L means "last" (don't apply further rewrite rules)
  • NC means "no case" (case insensitive so /NL/BUSINESS will also match -- this may not be what you want)
10
  • In the example URLs give, it looks like $1 will always be empty, so this could be simplified further.
    – MrWhite
    Commented Nov 24, 2016 at 9:47
  • i am getting 404 when I use this rule
    – prasanna
    Commented Nov 24, 2016 at 11:07
  • My guess is that you have other rewrite rules for Magento. You probably need to put this rule first and remove the L so that the Magento rewrite rules also work. Commented Nov 24, 2016 at 12:16
  • @StephenOstermiller i have updated the question with the htaccess rule,still it is returning 404
    – prasanna
    Commented Nov 25, 2016 at 3:50
  • @StephenOstermiller I have tried this rule also RewriteRule ^host.ip/nl/business/(.*) /$1 not working but i checked the rewrite rule in this website htaccess.mwl.be it is showing correctly
    – prasanna
    Commented Nov 25, 2016 at 3:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.