All Questions
Tagged with mod-rewrite apache
17,961 questions
0
votes
0
answers
43
views
PHP-FPM and Apache - setting SCRIPT_NAME
So far as I can tell, a simple installation of Apache and PHP-FPM (the versions supplied in the Debian 12 repository) results in different values for $_SERVER['SCRIPT_NAME'] from when Apache mod_php ...
0
votes
0
answers
15
views
.htaccess Hotlink prevention not working with [F], works with /403.html
I was trying to implement hotlink prevention on my site using .htaccess, but I encountered some issues.
I first tried this rule:
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(...
0
votes
1
answer
41
views
Permission denied: AH00529: /home/username/public_html/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
I'm seeing a lot of errors in apache error log:
(13)Permission denied: [client xyz:63932] AH00529:
/home/username/public_html/.htaccess pcfg_openfile: unable to check
htaccess file, ensure it is ...
0
votes
2
answers
32
views
.Htaccess Customize Query String
I am using the code below.
RewriteCond %{QUERY_STRING} ^brands=(.*)&features=(.*)$
RewriteRule ^products/([_A-Za-z0-9-]+)$ index.php?brands=%1&features=%2
However, this requires both values. ...
0
votes
0
answers
40
views
unexpected behavior in .htaccess when redirecting directory paths to a .php script
I'm working on a website template.
The idea is to have the following base directory structure:
template // template-only files, don't modify!
private // for internal usage
public // for ...
0
votes
1
answer
20
views
Apache rewrite - append the request to a script
I want to append the request to a script.
example.com -> example.com/d.php
example.com/css/style.css -> example.com/d.php/css/style.css
example.com/api/ShowPdf?bar=Foo -...
0
votes
1
answer
20
views
Require minimal length of key in query params with .htaccess
The keys of query params of URLs should have a minimal length, e.g. 6 characters, to be accepted. This should be filtered by .htaccess.
Example of URL being ok:
https://example.com/blogs/?...
1
vote
0
answers
23
views
apache 2.4, mod_rewite, htaccess: RewriteRule in <IF>
Got an inherited problem from a retired admin. We have a 1900+ line .htaccess and I have to consolidate as a first step.
Instead of writing 700 times
RewriteCond
RewriteRule
I'd like to group the ...
2
votes
1
answer
26
views
How to Set a RewriteRule Based on RewriteMap Lookup in Apache?
I’m trying to create a rewrite rule in Apache to match URLs not matching a specific value retrieved from a RewriteMap.
I have a RewriteMap defined as follows:
RewriteMap product_map txt:/path/to/...
0
votes
2
answers
64
views
.htaccess URL Rewrite Rule Not Working In Subdirectory of Existing WordPress Site on Apache
I am trying to get a redirect rule working in a subfolder so I can rewrite a URL from:
https://www.somesite.co.uk/api/FormEntries.php?id=1
To (which is how users would access the above to provide a ...
0
votes
0
answers
8
views
Apache: returning error based on existence of a file named in a query string
I have a page which is returned by https://myserver.com/login?z=XXXXXX
XXXXXX is a 6-character string such as ABC123.
I would like Apache to return an 403: Forbidden error response if file
%{...
0
votes
0
answers
38
views
How to block user agents using a RewriteMap?
I'm trying to create an Apache RewriteMap for user agents, but I'm stuck. This code works fine if the agent is a single word and matches the agent string exactly:
RewriteMap agent_map "txt:/...
0
votes
0
answers
39
views
Unable To Serve Webp Images Through htaccess
I'm having problem to serve webp format images through htaccess. I have followed https://www.digitalocean.com/community/tutorials/how-to-create-and-serve-webp-images-to-speed-up-your-website and https:...
2
votes
1
answer
70
views
How to write a clean URL with mod_rewrite using virtual dirs, actual dirs and variables as a combination
I have read prior questions and read tutorials and I do not understand mod_rewrite fully so I am posting here. My current .htaccess is:
Options +FollowSymLinks
RewriteEngine On
#### 1st set of rules....
1
vote
1
answer
84
views
.htaccess trying to create Clean URLs mod_rewrite
I have read prior SO questions and read tutorials and I do not understand mod_rewrite fully so I am posting here
Options +FollowSymLinks
RewriteEngine On
#Using THE_REQUEST for catching references ...
0
votes
0
answers
12
views
mod rewrite for removing ? from the url
Am using apache2, I require to remove the question mark from my url. For example if my url http://192.168.20.120/docs/pay/?2023/04/text.pdf I need to remove ? and result http://192.168.20.120/docs/pay/...
1
vote
0
answers
37
views
Using mod_rewrite to redirect all requests to another directory
This should be easy but apparently isn't.
My http.conf points mydomain.com to "/var/html/www".
In "/var/html/www" is a folder called "production" that contains another ...
2
votes
1
answer
94
views
.htaccess assistance with rewrite rule
I have trouble rewriting virtual directories as variables.. can someone help please?
The URL is:
https://www.example.com/content/index.php?var=1-dKein4i59xcNjfks
I want it to look like:
https://www....
2
votes
1
answer
43
views
Block specific regex in htaccess
There is a way to block all the requests with a certain querystring?
GET /?7eyS=cUYD HTTP/2
GET /?8dkG=TMWZ HTTP/2
GET /?viYF=4KbU HTTP/2
GET /?Wv3y=oCSA HTTP/2
2
votes
2
answers
60
views
Rewrite rule to resolve 2 use cases
I have a rewrite rule in my .htaccess file:
RewriteRule ^projects/?([a-zA-Z0-9-]+)?/?([a-zA-Z0-9-]+)?$ /projects/$1/seo.$2.php
For example, the following rule works fine and I would like to keep it ...
1
vote
1
answer
83
views
Apache rewrite condition - directory check not working for trailing slash
Within our virtual host config, I am trying to use a RewriteCond to check if a trailing slash request is requesting a .html page that exists on our website. If so, 302 redirect it to the proper .html ...
1
vote
1
answer
56
views
.htaccess 301 rewrite rules for wildcard automated rewrite rules
Can someone help me with doing a 1 line rewrite rule so that I don't have to do 1 by 1 for article urls
example of old URL:
olddomain.com/article/12/name-of-the-old-page.html
which I just want to ...
0
votes
0
answers
38
views
How to capture ProxyPassMatch response?
I have an apache proxy server setup that acts as a router between my multiple backends. The httpd.conf file is something like this
ProxyPassMatch "something/([^/]*)/(.*)" "http://$1/$2&...
0
votes
0
answers
47
views
how to use Apache LocationMatch *after* RewriteRule with QUERY_STRING
I'm using ProxyPass for two URLs (A and B below) that both include a question mark and the string 850: -
A: https://frontend.com/850/home?session=25575 -> https://backend.com/850/home?session=25575
...
1
vote
1
answer
39
views
.htaccess rule to implement root and subfolder in same way
we have a directory in which there is a index.php file, for which we have defined rule via .htaccess which is working fine, now we need to create a subdirectoy that will also have index.php file.
Now ...
0
votes
0
answers
29
views
Avoiding double redirects by .htaccess
By using the following .htaccess section I make sure that every URL is redirected to its https://www. version:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [...
0
votes
1
answer
40
views
.htacess unable to remove www from specific URLs
I have the following .htacess file:
RewriteEngine On
RewriteBase /
# Remove 'www' from the URL
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# Redirect ...
0
votes
0
answers
87
views
Redirect HTTP traffic to HTTPs on same port in Apache reverse proxy
I've got a reverse proxy operating on port 2000 using Apache.
It's listening to another web server on the same port which is broadcasting HTTP.
I can get the reverse proxy functioning fine, and HTTPS ...
0
votes
1
answer
36
views
Downloading Static Files via Apache-deployed Angular app
I have an Angular 15 webapp, deployed on Apache/2.4.53, on a CentOS server.
I have used Rewrite rules to redirect all requests for my app to the index.html, so that Angular can handle the routing ...
0
votes
1
answer
49
views
Apache config: RewriteRule in <If> block never rewrites
I'm customizing the configuration of Apache httpd (2.4.59). Here is one puzzle:
This rule rewrites matching URIs if unconditional:
RewriteRule ^/abc/.* /myscript.php [L]
But if coded this way, the ...
0
votes
1
answer
41
views
mod_rewrite: Error 500 triggered when URI contains an existing file without extension followed by /whatever when using REQUEST_FILENAME
What I want to do
If the requested resource in the URL has no extension and a file name matches the resource, use mod_rewrite to service that file. Otherwise, trigger error 404.
E.g. request is /foo ...
0
votes
0
answers
11
views
Apache 2.4 conditional doesn't match regexp
I'm trying to match a simple condition in apache virtual host to rewrite the original URL and redirect to the load balancer definition.
The condition should match against URL like
"https://...
0
votes
0
answers
19
views
Apache mod_rewrite - allow access to directory/
Apache 2.4 mod_rewrite .htaccess located in somedir
I want to deny access to everything in a directory except index.html and 403.html
Below works.
RewriteEngine On
RewriteCond %{REQUEST_URI} &...
1
vote
1
answer
51
views
Reading variable from a file into .htaccess causes an internal server error
What I'm Trying to Accomplish
I have more than 1,000 individual files in the format https://example.com/archives/<NNNNNN>.php where N is an integer.
I need to keep the existing structure as-is,...
0
votes
0
answers
10
views
How to rewrite a long URL to fix forwarding issue
I sent out some flyers with the url example.org/youth. Sadly, example.org resolves to https://www.example.org but example.org/youth resolves to a 404 error. How do I edit the .htaccess to make this ...
0
votes
0
answers
30
views
htacess rewrite directory inside directory
On my server the domain "domain.com" points to "/docroot/"
I would like to rewrite all requests from "domain.com/example1" to get files and directories located in:
"/...
0
votes
0
answers
19
views
Yet another .htaccess RewriteRule Condition not being met
This is the baseurl "http://tkrn.io/u/tkrn/1337test.exe" and I'm looking to rewrite it to "http://files.tkrn.io/tkrn/1337test.exe"
RewriteEngine On
RewriteRule ^u\/(.*)$ http://...
0
votes
1
answer
34
views
Apache redirect infinite loop
I want to have a redirect from
https://example.com/app/my.page
to
https://example.com/app/my.page?login=INTERNAL
but unfortunately I go into an infinite loop
I have some staging script for httpd.conf ...
0
votes
1
answer
37
views
ModRewrite rule - Skip if the selector is not present
I have a situation where I need to write urls with and without selectors seperately.
for example
the URI /feeds/mydata.json should go to /content/feeds/mydata/app.json
the URI /feeds/mydata.sale.json ...
0
votes
0
answers
23
views
httpd rewrite causing 404 loop
I have taken over an older project that is using Toro to serve routes in a PHP project, and I am having a hard time understanding exactly what it's doing. I believe my issue is in my apache mod ...
0
votes
1
answer
48
views
Compare two backreferences in RewriteCond
This is the old URI pattern /release-(\w+)/(\w+)/(.*), where first and second regex pattern are always the same, with the following examples:
/release-foo/foo/(.*)
/release-bar/bar/(.*)
etc
They are ...
1
vote
0
answers
66
views
Fixing Apache HTTPD Configuration for Blocking Specific Headers and Custom 403 Error Page
I'm facing an issue in Apache httpd. In the littpd.conf. Inside the rewrite.mod I am blocking requests which have these 3 headers
X-HTTP-METHOD
X-HTTP-Method-Override
X-METHOD-OVERRIDE
And the ...
0
votes
1
answer
67
views
Laravel project inside a legacy one
I'm trying to make a laravel project work inside a legacy site while we work on modernizing the entire code base. I've been able to make it work in my dev computer using valet creating a custom valet ...
2
votes
1
answer
40
views
Redirect default language parameter to root with htaccess
I have been looking for a solution, but only found one similar case without an answer (unfortunately). Although the implementation is working, I am still missing one crucial aspect.
I am running a ...
0
votes
1
answer
45
views
Redirect All URI Requests, Including Folders, to index.php Using .htaccess?
I am trying to configure my .htaccess file to redirect all URI requests, including folders, to index.php. Here is the structure of my root directory:
app
admin
public
index.php
.htaccess
My goal is ...
0
votes
0
answers
61
views
Best way to deny .php in URLs while keeping access to those files through other URLs
Here are two examples of what I would like to do:
Example 1: I have a services.php file. I would like it to be accessible on www.example.com/services. Furthermore, I would like www.example.com/...
0
votes
0
answers
20
views
RewriteRule issue after 5th rule
I am stuck in a viard issue.
I have the below set of RewriteRule configured in httpd.conf for one of my domain.
----
<Directory "/var/www/html/test/">
RewriteEngine On
...
0
votes
0
answers
22
views
Authorizing Access to apache http application using mod_rewrite rules
i am a bit new to apache web server and mod_rewrite .
We are hosting a cgi application on apache web server We are trying to add an authorization check to verify whether the user has access to the ...
0
votes
0
answers
23
views
Error Too many redirects when changed from Apache to Nginx
I have migrated my website from Apache to Nginx. I had issue after migration.
Current .htaccess configuration:
RewriteBase /
RewriteRule ^home$ index.php
RewriteRule ^file/? do.php?id= [QSA]
...
0
votes
0
answers
38
views
Apache mod_rewrite How to strip slash off document root AND all URIs
I have apache-2.4.59 on fedora40 and trying to strip any trailing slash(es) from the root and any other URIs using RewriteCond/RewriteRule in my vhost config. I've tried a dozen different combinations ...