What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Test the hostname with RewriteCond %{HTTP_HOST}, then match the requested path with RewriteRule. In a document-root .htaccess file, do not normally put a leading slash in the rule pattern.
Antihost offers Linux VPS plans with full root access, unlimited traffic on a 1 Gbps port and a 14-day free trial.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^app.example.com$ [NC]
RewriteRule ^(.*)$ app/$1 [L]
This internally maps https://app.example.com/docs/page.html to the app/docs/page.html path while leaving the browser on the subdomain.
As an Amazon Associate I earn from qualifying purchases.
What a subdomain rewrite rule actually matches
An Apache rewrite has two separate jobs: deciding whether a request qualifies and deciding which URL path Apache should serve. The hostname belongs in a RewriteCond; the URL path belongs in RewriteRule.
Apache’s documentation states that the RewriteRule pattern is matched only against the URL path, not the hostname, port, or query string. Consequently, a pattern such as ^app.example.com will not match a subdomain in .htaccess. Apache has already separated the host from the path by the time it evaluates the rule.
#1 Best Overall
- [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
- [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
- [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
- [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
- [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.
The normal arrangement is:
RewriteEngine Onenables rewriting for the directory.- One or more
RewriteConddirectives test the request, usually through%{HTTP_HOST}. - The following
RewriteRulematches the path and supplies a replacement path or URL. - Flags such as
[L],[END],[R=301],[NC], and[NE]control what happens next.
Conditions apply to the RewriteRule immediately below them. If several conditions are present, every condition must match before that rule is applied. Captures from a condition are referenced as %1, %2, and so on; captures from the RewriteRule itself are referenced as $1, $2, and so on.
Prerequisites before editing .htaccess
A syntactically correct rule cannot work if the request never reaches the Apache instance or if Apache is not allowed to read rewrite directives. Verify the following in order:
Free tools Windows power users keep installed
One-click scans. No signup required.
- DNS: The subdomain must resolve to the server handling the request. Check the DNS record for
app.example.comand confirm that it points to the intended service. - Virtual host: The request must arrive at the Apache virtual host that serves the expected document root. A different virtual host can make a correct rule appear ineffective.
- Module:
mod_rewritemust be available, and the file must containRewriteEngine On. - Override policy: The directory configuration must permit the rewrite directives used in
.htaccess. If Apache rejects them, the server administrator must adjust the directory’s override policy. - File location: Establish whether the file is in the document root or a subdirectory. Per-directory rewriting changes the path presented to the rule.
- Safe test: Start with a narrow path or a temporary redirect. Do not make a permanent redirect the first test.
If DNS or virtual-host routing is wrong, changing the regular expression will not solve the problem.
Internal rewrite: keep the subdomain in the address bar
Use an internal rewrite when the subdomain should be served from a directory inside the same document root. The server changes the resource it reads, but the browser does not receive a redirect and continues displaying the original host.
Document-root example
RewriteEngine On
RewriteCond %{HTTP_HOST} ^app.example.com$ [NC]
RewriteRule ^(.*)$ app/$1 [L]
With this file in the document root, a request for https://app.example.com/docs/page.html is served from the document-root path app/docs/page.html. The client still sees https://app.example.com/docs/page.html, not a URL containing /app.
The host expression is anchored with ^ and $. Anchoring prevents a name such as not-app.example.com or app.example.com.attacker.example from satisfying an otherwise loose expression. [NC] makes the host comparison case-insensitive, which is generally appropriate for hostnames.
Local testing on a non-default port
When testing locally on a port such as 8080, include the port in the condition instead of assuming that %{HTTP_HOST} contains only the name. A narrowly scoped test can be written as:
Rank #2
- 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
- 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
- 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
- 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
- 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
RewriteCond %{HTTP_HOST} ^app.example.com(?::8080)?$ [NC]
RewriteRule ^(.*)$ app/$1 [L]
The optional :8080 is for that local test arrangement; use the actual port you have configured, and remove it when the public request uses the default port.
Preventing the directory prefix from being added repeatedly
After an internal rewrite, per-directory processing can run again. A catch-all rule that always prepends app/ may therefore try to turn app/docs/page.html into app/app/docs/page.html. Put an exclusion ahead of the catch-all when the destination directory is visible during a later pass:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^app.example.com$ [NC]
RewriteRule ^app(?:/|$) - [L]
RewriteCond %{HTTP_HOST} ^app.example.com$ [NC]
RewriteRule ^(.*)$ app/$1 [L]
The first rule leaves paths that already begin with app/ alone. Add exclusions for other paths that must bypass the mapping, and place those exclusions before a broad rule.
Existing files and directories
A catch-all can also capture assets, administrative paths, or other resources that should be handled normally. Decide explicitly which files and directories belong outside the subdomain mapping. Exclude them before the catch-all, and stop processing after the intended match. Do not add a blanket exclusion without checking what the application actually needs.
External redirect: send the browser to another host
Use an external redirect when the visible URL must change. Apache returns a redirect response, and the browser makes a new request to the destination host.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old.example.com$ [NC]
RewriteRule ^/?(.*)$ https://www.example.com/$1 [R=301,END,NE]
This redirects requests from old.example.com to the corresponding path on www.example.com. The ^/? form tolerates an optional leading slash, although per-directory patterns normally do not receive one. The destination is an absolute URL because a visible redirect must tell the client where to go.
Choose the status deliberately
- 301: Use only when the move is intended to be permanent. Browsers and intermediaries can cache a permanent redirect, making mistakes difficult to undo quickly.
- Temporary status: Use the temporary status appropriate to your deployment while testing or when the move is not permanent. Replace it with 301 only after the behavior is confirmed.
The host condition must not also match the destination host. Redirecting every host to a URL whose hostname satisfies the same condition creates a loop. If HTTP-to-HTTPS canonicalization is also present, establish a clear order so that the two redirects do not send the request back and forth.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Rank #3
- [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
- [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
- [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
- [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
- [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
What the redirect flags mean
[R=301] asks Apache to return a permanent redirect. [END] stops per-directory rewrite processing after the redirect. [NE] prevents normal escaping in the redirect result; use it only when you understand the encoding consequences. For ordinary URLs, preserving safe URL encoding is the safer default.
Internal rewrite versus external redirect
| Decision point | Internal rewrite | External redirect |
|---|---|---|
| Browser address | Remains on the original subdomain and path | Changes to the destination URL |
| Typical substitution | Relative path such as app/$1 |
Absolute URL such as https://www.example.com/$1 |
| Response | Apache serves the mapped resource directly | Apache returns a redirect status, then the client requests the new URL |
| Destination host | Normally the same host | Can be a different host or canonical hostname |
| Document-root relationship | Destination remains inside the server’s mapped document tree | Destination may be another virtual host or server |
| Typical use | Serve a subdomain from an application directory without exposing that directory | Move a subdomain, enforce a canonical host, or make a migration visible |
Do not use a redirect merely to reach a directory that belongs to the same site unless exposing that path is intentional. Conversely, do not use an internal rewrite when clients, search engines, or other systems must learn the new canonical host.
How to construct the rule safely
1. Decide what must change
Write down whether only the server-side location changes or whether the public URL must change. That decision determines the substitution style and whether a redirect flag is appropriate.
2. Identify the exact host set
Use an anchored host condition for one subdomain:
RewriteCond %{HTTP_HOST} ^app.example.com$ [NC]
If more than one hostname is intentionally supported, use separate, clearly scoped conditions or a carefully designed expression. Avoid an unanchored fragment such as app, which can match unrelated hostnames.
3. Write the path pattern for .htaccess context
In a document-root .htaccess file, Apache removes the directory prefix before matching. The usual pattern is therefore ^(.*)$, not ^/(.*)$. A leading slash copied from a server-context example often prevents the rule from matching.
If the file is inside a subdirectory, the matched path is relative to that directory. Move the file or change the pattern only after confirming the directory context; do not assume a document-root rule behaves identically in a nested .htaccess file.
4. Preserve the path with a backreference
The capture in ^(.*)$ becomes $1. An internal substitution such as app/$1 adds the application directory while retaining the requested path. A redirect substitution such as https://www.example.com/$1 carries that path to the new host.
Rank #4
- Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
- Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
- All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
- Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
- Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
5. Add exclusions before broad rules
Place destination-directory exclusions, existing-file or existing-directory exceptions, and special application routes above a catch-all. The first matching rule may otherwise consume requests that another handler was supposed to process.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →6. Select the stopping flag
Use [L] to stop the current rewrite rule set after a match. In per-directory configuration, [END] is a stronger stop that ends all subsequent per-directory rewrite processing for the request. Choose [END] when another per-directory pass would be harmful; use [L] when later processing is intentionally allowed.
Why common attempts fail
“My RewriteRule does not match the subdomain”
The hostname was probably placed in the RewriteRule pattern. Move it to RewriteCond %{HTTP_HOST} and leave only the path in the rule. Confirm that DNS and the virtual host deliver the request to this Apache instance.
“The rule works in server configuration but not in .htaccess”
Check the leading slash first. Server-context examples and per-directory examples are not interchangeable: .htaccess normally receives a path with the directory prefix removed, so a pattern beginning with / can fail.
“The request becomes app/app/…”
The catch-all rule is being applied again after its own internal rewrite. Add a destination-path exclusion before the catch-all and stop the exclusion with [L] or use [END] where a complete per-directory stop is required.
“The browser keeps redirecting”
Inspect the host condition and the redirect target. A redirect loop occurs when the destination still satisfies the condition, or when separate HTTP-to-HTTPS and hostname rules repeatedly hand the request to each other. Make each canonicalization rule match only the non-canonical form and test each transition independently.
“Apache returns 500”
Read the Apache error log at the time of the request. Then verify that mod_rewrite is loaded, RewriteEngine On is present, the directives are permitted by the directory’s override policy, and the regular-expression syntax is valid. A server error is not evidence that the host condition is wrong; it often means Apache rejected the configuration before matching any request.
Best Value
“Nothing changes after I edit the file”
Confirm that the request is reaching the directory containing the edited file, that the intended virtual host is active, and that you are testing the exact hostname in the condition. A request sent to an IP address or a different host will not satisfy an anchored subdomain condition.
When VirtualHost configuration is the better choice
If you administer Apache’s server configuration, a dedicated virtual-host rule is usually cleaner for hostname routing than distributing host logic through a document-root .htaccess file. Apache’s remapping guidance identifies a dedicated Redirect in a <VirtualHost> as the cleanest approach when server-configuration access exists.
Recommended Free Tools
| Factor | .htaccess | VirtualHost/server configuration |
|---|---|---|
| Administrative access | Useful when you can edit only the site’s directory | Requires control of Apache’s server configuration |
| Scope | Per-directory and inherited according to the directory layout | Can target one virtual host directly |
| Maintainability | Convenient for site-level changes, but easy to duplicate or conflict | Centralized and easier to audit for host-wide routing |
| Performance | Read during per-directory request processing | Loaded as server configuration rather than discovered from directories |
| Typical redirect choice | RewriteRule with an absolute target | A dedicated VirtualHost Redirect when applicable |
Use .htaccess when that is the deployment boundary you control. If you can change the virtual-host configuration, keep hostname canonicalization there and reserve per-directory rules for behavior that genuinely belongs to the application tree.
A deployment and verification sequence
- Create or back up the current
.htaccessfile in the correct document-root directory. - Add
RewriteEngine Ononce, then add a narrowly scoped host condition. - Begin with an internal mapping or a temporary redirect and one known path, such as
/docs/page.html. - Request the exact subdomain and inspect both the browser URL and the returned resource. An internal rewrite should keep the original URL; a redirect should expose the new URL and status.
- Test a different hostname that must not match. It should bypass the subdomain rule.
- Test the destination directory and any existing files or directories that need exclusions.
- Check Apache’s error log for syntax or permission failures.
- Only after the behavior is stable, widen the path pattern and change a confirmed permanent move to status 301.
Keep host matching anchored, keep exclusions above catch-all rules, and document whether each rule is intended to be internal or visible. Those three decisions prevent most accidental loops and unexpected URL changes.
Practical templates
Subdomain to an application directory
RewriteEngine On
RewriteCond %{HTTP_HOST} ^app.example.com$ [NC]
RewriteRule ^app(?:/|$) - [L]
RewriteRule ^(.*)$ app/$1 [L]
This template assumes the file is in the document root. The first rule protects paths already under app/; the second maps the remaining paths. Add the host condition to the exclusion too when other hostnames share this file and must not see the exclusion.
Permanent move to another host
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old.example.com$ [NC]
RewriteRule ^/?(.*)$ https://www.example.com/$1 [R=301,END,NE]
Use this only when the hostname move is permanent and the target host does not satisfy the condition. During initial testing, use a temporary status instead of committing clients and caches to a 301.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteBottom line
For a subdomain in .htaccess, test the hostname with RewriteCond %{HTTP_HOST}, match the slashless per-directory path with RewriteRule, and choose the substitution based on whether the browser should see a new URL. Internal relative substitutions route requests inside the same document root; absolute URLs with an intentional redirect status change the public destination. Verify DNS, virtual-host routing, mod_rewrite, and override permissions before debugging expressions, then guard destination paths against repeated processing.
Quick Recap
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.




