How to Configure Magento 2 URL Rewrite Index?

How to Configure Magento 2 URL Rewrite Index?

Struggling with broken links and want cleaner URLs for better Magento SEO and UX? Magento 2 URL Rewrite Index rewrites old URLs to new ones. It prevents broken links and enhances the user experience.

This tutorial shows you how to set up, handle, and fix URL rewrites in Magento 2.

Key Takeaways

  • Magento 2 URL Rewrite Index redirects old URLs to new ones.

  • Search engines crawl cleaner URLs, which helps SEO.

  • The index stops duplicate content by managing URL rewrites.

  • Site upkeep gets simpler with automatic redirects and fewer manual changes.

  • Managing URLs for campaigns and promotions becomes easy with custom URLs.

What is Magento 2 URL Rewrite Index?

What is Magento 2 URL Rewrite Index

Magento 2 URL Rewrite Index is the system that manages URL changes behind the scenes.

While there’s no dedicated indexer, Magento stores these rewrites in the url_rewrite table. The system automatically creates rewrite entries when updating product URLs, reorganizing categories, or changing store views.

It links old URLs to new ones, ensuring visitors and search engines always reach the correct page. This avoids broken links and enhances site navigation. As your store grows, URL rewrites keep everything organized.

They also improve SEO performance. Search engines can crawl clean URLs without duplication issues. Properly configured rewrites help maintain traffic and preserve ranking, even when your site structure changes.

Why Use Magento 2 URL Rewrite Index?

Reason Explanation
Lift SEO Performance The URL Rewrite Index builds SEO-ready URLs. Relevant keywords fit into your URLs. Search engine rankings climb. Search engines crawl neat URLs well. URLs boost search result visibility. The index strengthens your Magento SEO plan.
Keep User Experience The URL Rewrite Index directs users to the right pages. Broken or dead links stop forming. Users avoid 404 errors. New pages load instead. Redirects keep users content. Bounce rates drop, and user engagement holds steady.
Stop Duplicate Content The URL Rewrite Index blocks duplicate content problems. Redirects avoid different URLs for one page. Search engines index the chosen URL. Content stays unique and strong. The index picks the ranking page.
Manage Links Better The URL Rewrite Index organizes URLs. All redirects sit in one spot. You edit redirects with ease. Site structure stays clean. Link management cuts errors.
Aid Campaigns & Promotions Custom URLs arise during special campaigns. The URL Rewrite Index handles many URLs for one page. Targeted URLs suit different campaigns. Tracking these URLs turns simple. The index keeps promotional offers in check.
Ease Site Upkeep The URL Rewrite Index cuts upkeep tasks. Pages move or rename, and the index redirects visitors. Manual URL updates fade. Missing redirects pose less risk. Site upkeep speeds up and gains efficiency.
Fit Changing URL Structures The URL Rewrite Index adjusts to URL structure shifts. Transitions happen without breaks. Old URLs redirect to new ones. Site consistency holds. Traffic loss stops. The index keeps your URL structure solid.
Better Site Navigation The URL Rewrite Index sorts your site’s structure. Short, clear URLs form. Visitors grasp page content from URLs. Navigation gets clearer. Users find needs faster and with ease.
Raise Conversion Rates Clean, user-ready URLs affect conversion rates. The URL Rewrite Index crafts simple, relevant URLs. Visitors trust clear URLs and click them. Engagement with your site grows. A clear URL structure lifts conversions.

How to Configure Magento 2 URL Rewrite Index?

Step 1: Add the Constructor

Inject the UrlRewriteFactory in your class.

protected $_urlRewriteFactory;

public function __construct(

`Context $context,`

`\Magento\UrlRewrite\Model\ResourceModel\UrlRewriteFactory $urlRewriteFactory`

) {

`$this->_urlRewriteFactory = $urlRewriteFactory;`

`parent::__construct($context);`

}

Step 2: Create the URL Rewrite Model

Create an instance of UrlRewriteFactory in your method.

$urlRewriteModel = $this->_urlRewriteFactory->create();

Step 3: Set the Store ID

Assign a store ID.

$urlRewriteModel->setStoreId(1);

Step 4: Mark it as a Custom Rule

Tell Magento it’s not a system-generated rewrite.

$urlRewriteModel->setIsSystem(0);

Step 5: Define a Unique ID Path

Generate and set a unique id_path.

$urlRewriteModel->setIdPath(rand(1, 100000));

Step 6: Set the Target Path

Provide the original URL you want to redirect to.

$urlRewriteModel->setTargetPath("www.example.com/customModule/customController/customAction");

Step 7: Set the Request Path

Define the new URL you want to create.

$urlRewriteModel->setRequestPath("www.example.com/xyz");

Step 8: Save the URL Rewrite

Save the model to store the rewrite rule.

$urlRewriteModel->save();

How to Create URL Rewrites in Magento 2?

Step 1: Plan the Rewrite

Write down the URL of the target page for redirection. Note the URL key of the original page. Visit each page. Copy the URL from the browser’s address bar. Accuracy stays high, and mistakes drop.

Step 2: Generate the Magento 2 URL Rewrites

Generate Magento 2 URL Rewrite Index

Head to Marketing in the Magento Admin Panel. Select SEO & Search. Click URL Rewrites. Type the URL key of the target page in the search filter. Press Search. Many redirects may show. Pick the one matching the right store view. Click Edit. Delete the old redirect if needed by clicking Delete and confirming.

Step 3: Add a New URL Rewrite

Adding Magento 2 URL Rewrite Index

Press the Add URL Rewrite button. Choose the Store under URL Rewrite Information. Enter the URL key of the page to redirect in the Request Path field. Keep the Request Path unique to avoid save errors.

Step 4: Enter the Target Path

Target Path of Magento 2 URL Rewrite Index

Insert the URL of the target page in the Target Path field. Use the full URL if the target sits on another site. Pick the right Redirect type:

  • Temporary (302)

  • Permanent (301)

Step 5: Write a Short Description

Add a brief description of the rewrite in the field. Check that Request Path and Target Path match before saving.

Step 6: Save the Rewrite

Click the Save button. The rewrite applies. The new rewrite tops the list.

Step 7: Test the Rewrite

Go to your site’s homepage. Type the Request Path into the browser’s address bar. The target page should load, not the original. The rewrite works right.

Difference between URL Rewrites & URL Redirects

Aspect URL Rewrite URL Redirect
Definition Changes how the URL looks in the browser. Alters the URL stored on the server.
Purpose Gives a clean, user-ready URL. Sends users and search engines to a new URL.
Types Lacks types; only alters the shown URL. Offers Temporary (302) or Permanent (301).
Impact on SEO Keeps the original URL structure for SEO. Affects technical SEO if mishandled.
Use Case Fits when altering a product, category, or page URL key. Suits permanent or temporary page destination shifts.
URL Storage Leaves the server’s stored URL alone. Updates the server’s stored URL.
User Experience Shows a new URL without redirecting. Redirects users to a different URL.
Caching The browser caches the rewritten URL. Redirects skip browser cache use.
Server Load Almost no server load. Raises server load a bit.

How to Troubleshoot URL Rewrite Index Problems in Magento 2

1. Check Web Server Rewrite Settings

Check Web Server Setting for Magento 2 URL Rewrite Index

  • Confirm that Web Server Rewrites work in your Magento setup. Go to Stores > Configuration > Web.

  • Open the Search Engine Optimization section. Set "Use Web Server Rewrites" to Yes. It rewrites URLs for better SEO and clean creation. Save your setup after changes.

2. Configure Product URL Settings

Product URL for Magento 2 URL Rewrite Index

  • Verify the 'Use Categories Path for Product URLs' setting. Head to Configuration > Catalog > Search Engine Optimization.

  • Set Use Categories Path for Product URLs to Yes. Category paths join product URLs for SEO gains.

  • Set 'Use Canonical Link Meta Tag for Products' to Yes. Duplicate content across pages stops.

3. Clear Magento Cache

Clear Magento Cache via Magento 2 URL Rewrite Index

  • Old cache data blocks URL updates. Visit System > Cache Management.

  • Flush the cache. Old data clears out. New settings take hold.

  • Check if the problem lingers. Refresh the cache after tweaks.

4. Update Redirect Rules

  • Fix redirect rules by hand if URLs fail. Go to the URL Rewrite Management section. Find existing redirects. Update the 301 Redirect rule if needed.

  • Example: Redirect 301 /store/bra_bust_lift.html /intimates/womens-intimates/bra-converters.html. Confirm the rule fits the right URLs. Test URLs after updates.

5. Verify Web Server and Nginx Configuration

  • Using Apache? Check if a server restart makes changes stick. Nginx users must confirm URL rewrite setup.

  • Wrong server settings block rewrites. Review settings. Restart if needed.

6. Check for URL Conflicts

  • Search for clashes among URL rewrites. Use URL Rewrite Management. Look for duplicate URLs.

  • Delete old ones if found. Each product, category, or CMS page needs one rewrite. Clear out extra or outdated redirects.

7. Test and Verify the Changes

  • Test URLs after these steps. Visit the product page. Check the URL format. Confirm it stays clean and correct.

  • Problems persisting mean repeat the steps. Look at logs for more info. Verification keeps all working before launch.

FAQs

1. How do URL Rewrites help SEO in Magento 2?

URL Rewrites build SEO-ready URLs with relevant keywords. Clean URLs lift your site in search results. Search engines crawl neat URLs. Search engine rankings rise, and duplicate content fades. A solid URL structure aids SEO.

2. Can I make custom URL Rewrites for promotional campaigns in Magento 2?

Magento 2 lets you craft custom URLs for campaigns and promotions. Target specific URLs for different audiences. Managing these links turns simple. The URL Rewrite Index tracks and updates links with ease. Right URLs match specific campaigns.

3. How does Magento 2 URL Rewrite Index handle site upkeep tasks?

The URL Rewrite Index cuts upkeep work. Pages move or rename, and users redirect without fuss. Manual URL updates drop away. Errors shrink. Visitors always reach the right page.

4. What steps fix URL Rewrites not working right in Magento 2?

Check that Web Server Rewrites run in the Magento setup. Clear the Magento cache to dump old data. Look for duplicate or clashing redirects. Remove unneeded ones. Review server settings. Wrong setups block rewrites.

Summary

Magento 2 URL Rewrite Index keeps URLs clean and lifts SEO. Site upkeep simplifies, and navigation gets better. Key perks include:

  • Clean URLs push search engine rankings up.

  • Redirects stop 404 errors for users.

  • Users hit the right page, dodging duplicate content.

  • URL redirects run on their own, cutting manual work.

  • Custom URLs aid campaign tracking.

For optimized URL handling, try managed Magento hosting for your ecommerce store.

Shivendra Tiwari
Shivendra Tiwari
Technical Writer

Shivendra has over ten years of experience creating compelling content on Magento-related topics. With a focus on the Magento community, he shares valuable tips and up-to-date trends that provide actionable insights.


Get the fastest Magento Hosting! Get Started