0

So, I have a rewrite rule that is supposed to redirect an old URL to a new one:

RewriteRule ^(.*)/-/manufacturers/(.*)$ $1/manufacturers--$2 [R=301,NC]

This is located in the .htaccess for the domain (though I've tested it in the /pub/.htaccess as well with no luck). However, when this rule is present in the .htaccess file, the URL doesn't become domain.com/category/manufacturers--name.html. Instead, it becomes domain.com/pub/category/manufacturers--name.html.

Where am I supposed to set up rewrite rules if not in the domain's root .htaccess?

2 Answers 2

1

The answer is you can put the rewrite rules in the same .htaccess file in the magento root. If you move them below the line "RewriteRule .* /pub/$0 [L]" they'll work. or you can exclude folders or files from the rule. I've found no "proper Magento method" of excluding certain folders or files since the change, so the workaround is to add rewrite conditions for the rule for anything you want to exclude.

Here is an example of what I added:

RewriteCond %{REQUEST_URI} !^.*/-/manufacturers/.*
RewriteCond %{REQUEST_URI} !^/php_info.php
RewriteCond %{REQUEST_URI} !^/pub/
RewriteCond %{REQUEST_URI} !^/setup/
RewriteCond %{REQUEST_URI} !^/update/
RewriteCond %{REQUEST_URI} !^/dev/
RewriteCond %{REQUEST_URI} !^/js/
RewriteRule .* /pub/$0 [L]

In this example, phpinfo.php was a file I wanted to view, and /-/manufacturers/ was a number of URLs for which I had written RewriteRules that I didn't want /pub/ prepended to. That should be enough info to apply it to anyone else's .htaccess.

0

For Magento 2.4 you need a module. Here is a great way to set one up: https://magento.stackexchange.com/a/158811/109113

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.