Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
.htaccess - string in url without subfolder

The URL is the following http://local.example.com/features.html and what I need is to add a text like "country" http://local.example.com/us/feature.html but with the code I have when I click on the URL the site shows a 404 error

This is only visual without creating a US sub-folder.

The code...

RewriteEngine On
RewriteCond %{HTTP_HOST} local.example.com$ [NC]
RewriteCond %{HTTP_COOKIE} location=us [NC] --> CHECK COOKIE FOR ACTION
RewriteCond %{REQUEST_URI} !^/us/  --> EXCLUDE US FOR REDIRECT LOOP
RewriteCond %{REQUEST_URI} !^/blog/ --> EXCLUDE BLOG FOLDER WITH WORDPRESS
RewriteRule ^(.*)!\.(css|js|png|jpg)$ http://local.example.com/us/$1 [R=302,L]
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

RewriteRule ^(.*)!\.(css|js|png|jpg)$ http://local.example.com/us/$1 [R=302,L]

The RewriteRule pattern will not match the requested URL (because of the erroneous !) so this directive won't actually do anything. From this I also assume you are wanting to exclude requests for CSS, JS, .png and .jpg files? You also have a condition that excludes requests made to a /blog/ subdirectory, however, you've not mentioned this in your question?

You also reference a cookie in the code? However, you've not mentioned this in your question and this won't work in its current state (since it won't be present on initial requests), so I'll ignore this for now.

Try the following instead:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^local\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg)$
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule !^us/ /us%{REQUEST_URI} [R=302,L]

The above states, given a request for /foo/bar...

  1. For any request that does not start with /us/
  2. And is for the Host local.example.com
  3. And is not for a URL that ends with either .css, .js, .png or .jpg
  4. And does not start with /blog/
  5. Then 302 (temporary) redirect to /us/foo/bar

Unless you have multiple hosts on this account, you don't need to explicitly check the Host header as part of the rule?

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!