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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Put a file named .htaccess in the directory that Apache uses as the subdomain’s document root. Apache then applies permitted directives in that directory and its descendants. If the server’s matching <Directory> block uses the default AllowOverride None, Apache ignores the file, so placement alone is not enough.

Find the subdomain’s document root, create the file with the exact name, enable the override categories required by your directives, and test one change at a time while watching the error log. If you administer the server configuration, Apache recommends putting rules in the virtual-host or <Directory> configuration instead of using .htaccess.

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

What an .htaccess file does for a subdomain

An .htaccess file is a per-directory Apache configuration file. For a subdomain such as sub.example.com, it affects requests only after Apache maps that hostname to a directory. Rules in that directory normally affect every file and subdirectory below it.

The file does not create a subdomain, select its DNS record, or change the virtual host that receives the request. Those jobs belong to DNS and the Apache virtual-host configuration. The file changes behavior after the request has reached the mapped directory—for example, URL rewriting, redirects, access controls, or authentication.

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application: attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Economical &Reusable: Built durable materials with a long-lasting battery,our CAGIWIRU air duster it's a sustainable alternative to disposable air cans.

Apache reads applicable configuration from parent directories and then more-specific directories. A parent file can therefore affect a subdomain whose document root is nested under a larger web root. A more-specific file can add rules or change settings where the directive permits it.

Requirements before you begin

  • Access to the directory mapped to the subdomain, through a control panel, SFTP, FTP, SSH, or a deployment system.
  • The exact document-root path for the subdomain.
  • An Apache server, or an Apache-compatible environment that actually processes .htaccess.
  • Permission from the server configuration to use each directive category you need.
  • Access to the Apache error log, or a hosting-panel view of that log.
  • For rewriting, the mod_rewrite module must be loaded. For file-based Basic authentication, the relevant authentication modules must be loaded.

On a server you control, the administrator must configure the matching <Directory> block. On managed hosting, the provider may expose an “Apache settings,” “AllowOverride,” or similar control, or may refuse changes to those settings.

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

Step 1: Identify the subdomain’s document root

Do not assume that the subdomain uses the main site’s public directory. A host may map sub.example.com to a path such as /var/www/sub.example.com/public, /home/account/sub.example.com/public_html, or a directory selected in a control panel.

Using a hosting control panel

Open the domain or subdomain management screen and look for a field labeled Document root, Web root, Home directory, or Path. Copy the path exactly. Some panels display a relative path; resolve it against the account’s home directory before uploading the file.

Using Apache configuration

Inspect the virtual-host definition for the subdomain. The DocumentRoot directive identifies the directory Apache serves. The relevant override policy is normally in a matching <Directory> block, which can be in the virtual-host file or a global configuration file.

<VirtualHost *:443>
    ServerName sub.example.com
    DocumentRoot /var/www/sub.example.com/public

    <Directory /var/www/sub.example.com/public>
        AllowOverride FileInfo AuthConfig
        Require all granted
    </Directory>
</VirtualHost>

The example shows the relationship between the hostname and directory; use your own paths and existing access policy. Editing a virtual-host file usually requires administrator privileges and a configuration reload.

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.
Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth

Confirming the path without guessing

Place a harmless test file such as root-check.txt in the suspected directory, request https://sub.example.com/root-check.txt, and remove the file after the response confirms the mapping. Do not leave diagnostic files containing server paths or credentials in a public directory.

Step 2: Create and upload the file correctly

  1. Create a plain-text file whose complete name is .htaccess. It has no filename before the dot and no extension after it.
  2. Save it with normal text encoding. Avoid a word processor, rich-text format, or an editor that silently adds .txt.
  3. Upload it directly into the subdomain’s document root, not into the account’s home directory unless that is the document root.
  4. Set ownership and permissions consistent with the other web files. The web server must be able to read the file, but it should not be writable by every system user.
  5. Request a known URL on the subdomain and check the error log after each subsequent edit.

Apache recognizes the filename .htaccess by default. A server administrator can change the name with the AccessFileName directive; unless that has been deliberately changed, another filename will not be read.

Step 3: Allow the directives you intend to use

Apache’s default AllowOverride None prevents .htaccess from changing server behavior. The administrator must enable the appropriate override category in the directory that contains the subdomain root.

Task Typical directives Required override category
URL rewriting and redirects RewriteEngine, RewriteCond, RewriteRule FileInfo
Basic authentication and access requirements AuthType, AuthName, AuthUserFile, Require AuthConfig
Named-directive control Specific directives selected by the administrator AllowOverrideList, where supported and configured

A typical directory policy for both rewriting and file-based authentication is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<Directory /var/www/sub.example.com/public>
    AllowOverride FileInfo AuthConfig
</Directory>

Use the narrowest policy that satisfies the application. Enabling every override category gives the directory user more control than necessary and can make accidental or malicious configuration changes harder to contain.

When AllowOverrideList is preferable

AllowOverrideList can permit named directives without enabling an entire category. This is useful when an administrator wants an application to use a small, explicit set of directives. The exact list must match the directives in the file and the Apache version’s supported syntax; an omitted directive remains disallowed.

Rank #3
Sale
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black | LED mouse pad with 14 lighting modes, covers keyboard & mouse, anti-slip rubber base, waterproof surface, USB powered
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

Step 4: Add and test rewrite rules

Turn on the rewrite module in the server configuration and then enable it in the file:

RewriteEngine On

In .htaccess context, Apache removes the directory prefix—and the leading slash—from the URL before matching a RewriteRule pattern. Thus a request for /images/logo.svg is matched as images/logo.svg, not /images/logo.svg. A rule copied from a virtual-host example may therefore fail until its pattern is adjusted.

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

Redirecting direct HTTP requests to HTTPS

If Apache itself receives the client’s TLS connection, a basic subdomain-specific redirect can look like this:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://sub.example.com%{REQUEST_URI} [R=301,L,NE]

The fixed hostname avoids redirecting to an arbitrary host header. Test with a temporary 302 response before switching to 301, because browsers cache permanent redirects aggressively.

This condition is deployment-specific when a reverse proxy, load balancer, or CDN terminates TLS before forwarding the request to Apache. In that arrangement Apache may see an internal HTTP connection even though the visitor used HTTPS. Do not copy the rule blindly; have the administrator define a trusted proxy-header policy and use only headers that the proxy overwrites safely. An untrusted client-supplied header can create redirect loops or security problems.

Preventing an accidental loop

  • Check whether the request already arrives at Apache as HTTPS.
  • Confirm that the proxy’s forwarded-protocol information is trusted and interpreted consistently.
  • Use browser developer tools or curl -I to inspect each Location response.
  • Remove or temporarily disable the last rule if the response alternates between two URLs.

Rules for a subdirectory application

When an application lives below the document root, include the directory context in the pattern and test both a real file and an application route. For example, a front controller might use:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

This sends requests that are not existing files or directories to index.php relative to the current directory. The application’s own routing, canonical-host policy, and trailing-slash behavior still determine whether this is appropriate. Keep unrelated rules in separate, commented blocks so that a later change can be identified quickly.

Step 5: Protect a subdomain with Basic authentication

For a private staging area or administrative directory, a minimal file is:

AuthType Basic
AuthName "Restricted Files"
AuthUserFile "/path/outside/document-root/.htpasswd"
Require valid-user

Set AuthUserFile to the real absolute path of a password file outside every publicly served directory. The file must be readable by Apache but must not be downloadable through a URL. Create and manage its entries with the password-file utility supplied by the server administrator.

The matching directory configuration must allow AuthConfig. Apache also needs the authentication modules that implement Basic authentication, file-based user lookup, and authorization. A missing module or a disallowed directive commonly produces a 500 response rather than a password prompt.

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

Basic authentication encodes credentials for transport; it does not encrypt them. Use TLS with mod_ssl for any account or content that matters. Do not treat a password prompt as a substitute for application authorization, multi-factor authentication, or a secure network boundary.

How inheritance and rule order affect a subdomain

Apache searches for applicable configuration in parent directories and applies it in order before processing more-specific directories. If the subdomain root is inside a main site’s tree, a parent .htaccess may add redirects, rewrite rules, or access requirements that were written for the main site.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.

Inspect every parent directory between the filesystem root and the subdomain root when behavior seems inexplicable. A child file may need to stop or supersede a parent rule, but the exact mechanism depends on the directive and Apache version. For rewrites, flags such as [L] stop the current per-directory pass; they do not necessarily prevent another pass or another parent-level rule from running.

Keep subdomain-specific rules in the subdomain root whenever possible. If the subdomain requires a fundamentally different policy, giving it a separate document root and a dedicated virtual-host configuration reduces accidental inheritance.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Testing procedure after every edit

  1. Save a backup of the last known-good file.
  2. Make one small change, then request a harmless URL on the subdomain.
  3. Check the HTTP status, response headers, final URL, and page content.
  4. Test a real file, a nonexistent path, and—if relevant—an authenticated path.
  5. Read the Apache error log immediately. Syntax and permission errors are easiest to match to the edit that caused them.
  6. Use a temporary redirect status while validating redirect logic; change to a permanent status only after the destination and conditions are correct.
  7. Remove diagnostic files and comments that disclose sensitive filesystem details before treating the configuration as finished.

For command-line checks, curl -I https://sub.example.com/path shows response headers and redirect status without downloading the body. Follow redirects separately with curl -IL when you need to see the complete chain.

Troubleshooting common failures

The file has no effect

  • Verify that it is in the actual subdomain document root, not merely in the main domain’s root.
  • Check for an accidental name such as .htaccess.txt or incorrect capitalization.
  • Ask the administrator to inspect the matching <Directory> block. AllowOverride None causes Apache to ignore the file.
  • Confirm that the request is reaching Apache and the expected virtual host rather than a proxy or different server.
  • Check parent directories for another file or rule that changes the result.

The change causes a 500 Internal Server Error

  • Read the Apache error log before changing several lines at once.
  • Look for a syntax error, an unknown directive, a missing module, or a directive forbidden by the current override policy.
  • Check each directive’s documented override requirement and remove the last edit to restore service.
  • Validate the configuration in a staging path when the hosting environment provides one.

A rewrite goes to the wrong path

  • Remove the leading slash from the RewriteRule pattern in .htaccess context.
  • Remember that the directory prefix is already implicit.
  • Check whether a parent rule runs first or whether a previous rule has already changed the URL.
  • Review the [L], [END], redirect, and query-string behavior required by your Apache version and application.

HTTPS redirects loop

Determine whether TLS terminates at a proxy. If it does, configure trusted forwarded-protocol handling instead of relying on %{HTTPS} alone. If Apache receives TLS directly, inspect the condition and confirm that the destination is already HTTPS.

The password prompt fails

  • Confirm that AllowOverride AuthConfig is enabled for the directory.
  • Check the absolute AuthUserFile path, file ownership, and read permissions.
  • Verify that the Basic authentication, file authentication, and authorization modules are loaded.
  • Read the error log for an invalid user-file format or an authorization failure.
  • Test over HTTPS so credentials are not exposed in transit.

.htaccess versus main Apache configuration

Both approaches can implement redirects, rewrites, and access controls, but they suit different operating conditions.

Consideration .htaccess Virtual-host or <Directory> configuration
Access required Directory or hosting-account access may be sufficient, provided overrides are enabled. Root or administrator access is normally required.
Where rules live Inside the document root or another applicable directory. In the server or virtual-host configuration.
Performance Apache checks for applicable files during request processing and directory traversal. Configuration is loaded as server configuration rather than discovered per request.
Security control People who can write the directory can modify permitted server behavior. Administrators retain centralized control over allowed directives and changes.
Provider support Useful on managed hosting and control-panel plans that explicitly support .htaccess. Available when you control the Apache installation or have an administrator who will change it.
Operational flexibility Individual applications can change their own permitted settings without a global reload. Centralized review, validation, and reload procedures are required for changes.

Apache documents .htaccess as a way to make per-directory changes without editing the main server configuration. When you do have configuration access, Apache recommends the main configuration because .htaccess introduces directory checks during requests and gives directory users the ability to alter server behavior.

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

Security and maintenance practices

  • Use the smallest AllowOverride category—or an explicit AllowOverrideList—that supports the application.
  • Keep .htpasswd and other secrets outside the document root.
  • Use HTTPS for Basic authentication and any private content.
  • Do not copy rewrite conditions designed for a different proxy, hostname, or directory layout.
  • Store the file in version control when possible, and review changes like application code.
  • Keep a known-good version available so a syntax error can be reverted quickly.
  • Comment the purpose and assumptions of non-obvious rules, especially proxy and canonical-host logic.
  • Prefer a dedicated virtual host and document root when the subdomain has a different security boundary from the main site.

Final setup checklist

  • The DNS record points to the server that owns the intended Apache virtual host.
  • The virtual host maps the subdomain to the directory where the file was uploaded.
  • The filename is exactly .htaccess, unless the administrator deliberately changed AccessFileName.
  • The matching <Directory> block allows the categories required by the directives in use.
  • mod_rewrite and any authentication modules required by the file are loaded.
  • Rewrite patterns account for the missing leading slash in per-directory context.
  • Parent-directory rules have been inspected for inheritance or conflicts.
  • Each change has been tested with status checks and the error log.
  • Password files are outside the document root and protected by HTTPS.
  • A rollback copy of the last working configuration exists.

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.