Questions tagged [mod-rewrite]

mod_rewrite is an Apache module that allows for server-side manipulation of requested URLs.

For an introduction and examples of using mod_rewrite, read over the comprehensive article,
"Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask"

2224 questions
1
vote
1 answer

htaccess syntax issue when moving script to a subfolder

I have recently purchased a script but this script only works in public_html folder . I need to install it in a subfolder named shop ( public_html/shop/ ) . Now the following .htaccess rules work perfectly when the script is placed in public_html…
Mr Pro
  • 33
  • 3
1
vote
1 answer

htaccess, block access a url with parameters

If I want to block access to example.com/path/?xxxx (xxxx is variable), but allow access to example.com/path/, how should I write it in my .htaccess?
Sanata
  • 11
  • 3
1
vote
1 answer

RewriteCond rules from apache to nginx

RewriteCond %{TIME_SEC} >40 RewriteCond %{TIME_SEC} <56 RewriteRule ^(.*)the-product(.*)$ https://www.%{HTTP_HOST}/%{REQUEST_URI} [R=301,L] I want to convert it to nginx but there is no solution for it to run for a fixed time RewriteCond…
Long MMO
  • 11
  • 2
1
vote
1 answer

.htaccess redirect if param value not portuguese-pt (FORCE WHMCS ONLY ONE LANG)

I need help to redirect URLs with multiple language codes to one with .htaccess. The following URLs should…
1
vote
0 answers

Automatically remove Set-Cookies

I have a php web application. This web application sets some cookies. I want to write a .htaccess which remove on the fly this cookies. Here is what I've done, with mod_header: Header unset Set-Cookie It works fine, but I have a problem: This line…
Bob5421
  • 319
  • 3
  • 8
  • 16
1
vote
0 answers

Rewrite rules for all but one directory (recursive)

We need to do a rewrite for a subdirectory of a site to its own host, with the exception of one directory. We also need to be sure that the original subdirectory is dropped in the rewrite. (using hppts instead of https because otherwise the site…
1
vote
1 answer

RewriteCond for APIKEY

I am trying to create a RewriteRule which looks at the incoming Header for an APIKey and if it contains a matching string then it will redirect to respective URL else, it should be inaccessible. I am testing this scenario using postman with Post…
1
vote
1 answer

On Apache how to switch off DirectorySlash only for requests to a specific subdomain?

Served by Apache I'd like on one subdomain site of mine (say sub.mydomain.com) that URLs without trailing slashes point directly (without external redirect) to the index file in the underlying folder. The subdomain requests are internally redirected…
halloleo
  • 123
  • 7
1
vote
1 answer

Forbidden on everything except for scripts located on subfolders

I want to forbid everything coming on a specific domain (e.g. example.com) except for some entry points (here, PHP files) located on a specific path (e.g. example.com/subfolder1/subfolder2/script.php). Here's a snippet of the configuration I used…
alxsbn
  • 113
  • 2
1
vote
1 answer

Trying to get Apache to serve webp instead of png/jpg (from /img folder of prestashop)

First post here, so I hope I did it well. I converted all png/jpg starting from my prestashop public_html folder to webp, and added rewrite rules to the .htaccess in order to have the webp served instead of png/jpg. I based my rewrites on the…
Totoro
  • 13
  • 4
1
vote
1 answer

Add a subdomain as an exception in hotlinking

I used this code in my .htaccess file and it is working great to prevent hotlinking: RewriteEngine On RewriteCond %{HTTP_HOST}@@%{HTTP_REFERER} !^([^@]*)@@https?://\1/.* RewriteRule \.(gif|jpg|jpeg|png|tif|pdf|wav|wmv|wma|avi|mov|mp4|m4v|mp3|zip?)$…
jeff
  • 11
  • 1
1
vote
1 answer

Consolidating many VirtualHosts into one block, is this a job for SetEnvIf?

Edit I think what I need here is SetEnvIf I'm attempting to consolidate all of my port-80 VirtualHosts into one block for convenience, but I'm struggling with the final piece of the puzzle. All port 80 vhosts accept a www and non-www connection to…
Jeff
  • 1,416
  • 3
  • 28
  • 50
1
vote
1 answer

RewriteRule won't match if trailing slash present, throws nginx 404

With this .htaccess... RewriteEngine on RewriteRule ^foo$ foo.php RewriteRule ^foo/$ foo.php ...I get the following behavior, when I request /foo — works, I get foo.php /foo/ — fails unexpectedly with a bare 404 from nginx /foobar — fails, as…
kubi
  • 121
  • 6
1
vote
0 answers

Apache reverse proxy to site using NTLM authentication fails with mod_rewrite but not mod_proxy

We have a reverse proxy server in front of an Exchange server and would like to lock down more of the paths. Minimized examples: Fails (but works for all pages that don't require authentication): ServerName…
melds
  • 231
  • 2
  • 9
1
vote
2 answers

.htaccess mod_rewrite not catching all RewriteRules

There is a PHP application with a PHP router as entry point for all the requests placed inside index.php. I am trying to write a .htaccess file to forward every request to index.php except for API requests and for design resources. So I am trying to…
caffeine
  • 113
  • 5