October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Enable mod_rewrite for Apache on CentOS

A practical CentOS guide to loading Apache mod_rewrite, enabling RewriteEngine in the correct context, configuring .htaccess permissions, validating httpd and troubleshooting ignored rules.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To enable mod_rewrite on CentOS, first verify that Apache has loaded the rewrite module, then turn on the rewrite engine in the configuration context where your rules will run. In a server or virtual-host configuration, add RewriteEngine On alongside your rules. In .htaccess, also make sure the enclosing <Directory> block allows the required overrides and that the directory meets Apache’s symbolic-link option requirements.

The configuration test must pass before you reload httpd. If rules work in one virtual host but not another, enable the engine separately in each host; Apache does not inherit rewrite configuration between virtual hosts by default.

As an Amazon Associate I earn from qualifying purchases.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What enabling mod_rewrite actually changes

mod_rewrite is Apache’s URL-rewriting module. Loading the module makes rewrite directives available; RewriteEngine On turns the runtime rewriting engine on for the configuration context in which it appears. The module can be loaded while the engine remains off, so both checks matter.

Apache permits rewrite directives in server configuration, virtual-host configuration, directory sections and per-directory .htaccess files. The context determines the rules’ scope, the permissions required to use them and how a rule pattern is matched. A rule in the wrong context can therefore appear syntactically correct but never run.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.
  • Module loading: Apache must recognize the rewrite_module module.
  • Engine state: the relevant context must contain RewriteEngine On.
  • Permissions: a directory using .htaccess must permit the required override class.
  • Filesystem options: per-directory rewriting requires an appropriate FollowSymLinks or SymLinksIfOwnerMatch setting.
  • Validation: test the complete Apache configuration before reloading the service.

These are separate stages. Installing or loading the module does not automatically activate rewrite processing in every virtual host or directory.

Check the active CentOS Apache installation first

CentOS installations can differ by release, package source and local administrator changes. Identify the Apache package and the configuration tree that the running service actually uses before editing anything.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Confirm that the Apache package is installed and that the service is named httpd on your system.
  2. Inspect the active Apache configuration and the /etc/httpd/ tree commonly used by CentOS. Look for the main configuration file, included configuration files and the distribution’s module include file.
  3. Follow the existing include structure instead of creating a second, parallel configuration layout. A file that is not included by the active configuration has no effect.
  4. Back up the file you intend to edit, or make the change in a separate included file that is clearly associated with the relevant virtual host.

Do not assume that a path from another CentOS release applies unchanged to your server. The decisive test is whether the running Apache configuration includes the file and accepts its directives.

Verify that mod_rewrite is loaded

Find the module declaration in the active module configuration. A typical declaration is:

LoadModule rewrite_module modules/mod_rewrite.so

Retain the declaration supplied by the distribution when it is already present. Do not add a duplicate line merely because you found a different module file elsewhere. Duplicate or conflicting declarations can create a new configuration error without enabling anything useful.

If Apache reports RewriteEngine as an unknown directive, the immediate question is whether the configuration that contains the directive also loads rewrite_module. Check the included module files and then run the Apache configuration test. A successful package installation alone does not prove that the active service has loaded the module.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

After confirming the module declaration, place a minimal engine directive in the context you plan to use. The directive is:

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed
RewriteEngine On

That line controls rewriting only in its own context. It is not a global switch that automatically activates rules everywhere.

Choose where your rewrite rules will live

Use server or virtual-host configuration when you administer Apache. It provides centralized control and makes validation and deployment easier. Use .htaccess when per-directory delegation is intentional—for example, when the directory owner must manage rules without editing the main server configuration.

Characteristic Server or virtual-host configuration .htaccess configuration
Administrative control Requires access to Apache’s main or virtual-host configuration. Allows delegated, per-directory rule management when the server permits it.
Scope Can apply to the server or to one selected virtual host. Applies to the directory containing the file and its per-directory processing context.
Inheritance Rewrite configuration is not inherited by virtual hosts; each host that needs rules must enable its own engine. Rules are processed for the directory hierarchy governed by the file, subject to the enclosing directory configuration.
Override permission Does not depend on AllowOverride for the rule itself. Requires an enclosing <Directory> policy that allows the needed override directives; AllowOverride None causes Apache to ignore the file.
Symbolic-link requirement Can set the applicable directory options directly in server configuration. Per-directory rewriting requires FollowSymLinks or SymLinksIfOwnerMatch; setting that option in the file also depends on override permissions.
Centralized validation All rules can be checked with the main Apache configuration test before a reload. Rules are discovered during request processing, so a file can be silently ignored if directory permissions do not allow it.

Do not mix the two approaches accidentally. A rule copied from a virtual-host block into .htaccess may need a different pattern, and a rule intended for one host can affect more traffic when placed at server scope.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Enable rewriting in server or virtual-host configuration

1. Locate the correct virtual host

Open the configuration block for the host that serves the URL you need to rewrite. If the rule belongs to the default server rather than a named host, use the relevant server-level configuration. Make sure the file is included by Apache.

2. Turn on the engine and add conditions or rules

A minimal virtual-host fragment looks like this:

<VirtualHost *:80>
    ServerName example.test
    DocumentRoot /var/www/example

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
</VirtualHost>

The example demonstrates placement, not a universal application design. Replace the host, document root and rule logic with the values required by your application. Keep RewriteEngine On inside the same virtual-host context as the rules that depend on it.

3. Repeat the directive for every host that needs rewriting

Apache does not inherit rewrite configurations by default between virtual hosts. If two hosts have separate rule sets, put RewriteEngine On and the appropriate rules in both virtual-host blocks. A rule working on one host is not evidence that the module or engine is active on another.

4. Avoid duplicate module declarations

The virtual-host block needs the engine and rules, not another LoadModule line. Keep module loading in the distribution’s module configuration area and keep host-specific behavior in the host configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Enable mod_rewrite through .htaccess

1. Permit the file in the enclosing Directory block

Apache ignores .htaccess completely when the enclosing <Directory> configuration uses AllowOverride None. Change the directory policy only if delegated configuration is appropriate for the server.

The FileInfo override group includes RewriteEngine, RewriteOptions, RewriteBase, RewriteCond and RewriteRule. The enclosing policy must permit the directives your file uses. A representative directory block is:

<Directory /var/www/example>
    AllowOverride FileInfo
    Options FollowSymLinks
</Directory>

Use the exact options and override policy required by your installation. If other directives in the file belong to additional override groups, permitting only FileInfo will not make those unrelated directives valid.

2. Put the file in the directory Apache serves

Create or edit the .htaccess file in the document directory governed by the matching <Directory> block. A file in a different filesystem directory is not consulted merely because it has the right name.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

3. Enable the engine inside the file

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

In per-directory and .htaccess context, Apache removes the directory prefix before matching the rule pattern. Consequently, a pattern normally omits the leading slash that you might expect from the browser URL. This context difference is a common reason that a rule appears not to match.

4. Satisfy the symbolic-link option requirement

Per-directory rewriting requires either FollowSymLinks or SymLinksIfOwnerMatch, according to the active directory configuration. If you try to set the option in .htaccess, the applicable override permissions must allow that option as well. An options error is therefore both a filesystem-option issue and a permissions issue.

Understand rule context before debugging a pattern

The same textual rule can behave differently depending on where it is evaluated. Server and virtual-host rules see a different URL path representation from per-directory rules, while .htaccess processing strips the directory prefix before pattern matching.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC
  • Check whether the rule is in server, virtual-host, directory or .htaccess context.
  • For .htaccess rules, test the pattern without a leading slash unless your specific rule design requires otherwise.
  • Keep conditions immediately associated with the rule they qualify so that a later rule does not accidentally use them.
  • Use the narrowest context that matches the intended scope; a server-wide rule can affect hosts and paths you did not mean to change.

When diagnosing a mismatch, first establish that Apache is reading the file and that the engine is on. Only then adjust the pattern or condition.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Validate, reload and test safely

1. Run the Apache configuration test

Use the configuration-test command provided by your CentOS Apache installation before reloading the service. On many installations this is httpd -t or the equivalent apachectl configtest. Use the command that corresponds to the active service and package.

Do not reload after a failed test. Correct syntax errors, unknown directives, duplicate declarations or invalid paths first, then run the test again until Apache accepts the complete configuration.

2. Reload through the service manager

Once the test succeeds, reload httpd with the system service manager so the new configuration is applied. A reload normally avoids stopping the service, while a restart may be appropriate when your deployment procedure requires it. Follow the service manager’s result and check for an error before moving on.

3. Request a URL that should match

Use a client such as a browser or curl to request a path covered by the rule. For redirects, inspect the HTTP status and the Location response header. For internal rewrites, verify the application response rather than expecting a changed browser address.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -I http://example.test/old-path

This command shows response headers; it does not prove that every application path works. Test representative paths, including one that should bypass the rule when your conditions distinguish existing files or directories.

4. Read the Apache error log when behavior is unexpected

Review the error log associated with the server or virtual host. The log can reveal an unknown directive, a disallowed option, a malformed rule or a filesystem path problem. Do not call a rewrite change successful until the expected request behavior has actually been observed.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

Troubleshoot common failures

“RewriteEngine” is an unknown directive

Apache has not loaded rewrite_module in the active configuration, or the file containing LoadModule is not included. Confirm the module declaration, remove duplicate or obsolete declarations, run the configuration test and reload only after it passes.

Rules in .htaccess are ignored

Inspect the matching <Directory> block. AllowOverride None tells Apache to ignore .htaccess files completely. Permit the FileInfo directives used by the file, and verify that the file is located beneath the directory block that governs the request.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The rule works in one virtual host but not another

Place RewriteEngine On and the required rules in each virtual-host configuration that needs them. Rewrite settings are not inherited automatically between hosts, even when they share the same server process.

A per-directory rule produces an options error

Check whether the relevant directory has FollowSymLinks or SymLinksIfOwnerMatch. If the option is being set inside .htaccess, confirm that the override policy permits it. Fix the directory policy or move the option to server configuration where you have administrative control.

A rule matches the wrong path

Recheck the context. In directory and .htaccess processing, Apache removes the directory prefix before matching. A pattern copied from a server-level rule may therefore contain an unwanted path prefix or leading slash.

The configuration test fails after an edit

Read the first reported error and inspect the surrounding lines. Typical causes include a directive in a context where it is not allowed, a misspelled module name, an invalid option, a duplicate module declaration or an included file with a syntax error. Restore the last known-good file if necessary, then reapply one change at a time and test after each change.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A repeatable CentOS checklist

  1. Identify the running httpd package and active include tree.
  2. Confirm that LoadModule rewrite_module modules/mod_rewrite.so is present once in the active module configuration.
  3. Choose server, virtual-host, directory or .htaccess context based on who should administer the rules and how broadly they should apply.
  4. Add RewriteEngine On in every context that needs rewriting.
  5. If using .htaccess, ensure the enclosing directory does not use AllowOverride None and permits the FileInfo directives used by the file.
  6. For per-directory rewriting, provide FollowSymLinks or SymLinksIfOwnerMatch and the permissions needed to set it.
  7. Account for the directory-prefix difference when writing patterns.
  8. Run the platform’s Apache configuration test.
  9. Reload or restart httpd through the system service manager only after the test succeeds.
  10. Request a matching URL, inspect status and Location headers for redirects, and read the error log if the result differs from the rule’s design.

The cleanest arrangement for an administrator-controlled CentOS server is usually a virtual-host or server configuration, because scope and validation remain centralized. .htaccess is appropriate when per-directory delegation is a deliberate requirement, but it adds dependencies on AllowOverride, directory options and the filesystem location of the file.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.