All Questions
2,566 questions
1
vote
1
answer
74
views
How to ignore case in regexp mapping in a .htaccess rewrite rule? [duplicate]
What I have now is the following:
RewriteRule ^([^/]+)/*$ x/$1.html [L,NC,END]
This would point:
/abcd to x/abcd.html
/ABCD to x/ABCD.html
which would not be fine on a Unix file system that is ...
0
votes
1
answer
50
views
mod rewrite split and replace
I need an internal redirect, where category-slug is a dynamic value,
that schould be appended after the ~
/category/**category-slug** /blog/?ucterms=category~**category-slug**
Is that possible with ...
2
votes
2
answers
80
views
htaccess - rewriting API requests to "api.php" and other requests to "web.php"
I'm testing some stuffs on Apache server and PHP. at the root of my project, I have this
.htaccess configuration file:
RewriteEngine On
RewriteBase /react/
# API requests
RewriteCond %{REQUEST_URI} ^/...
2
votes
2
answers
80
views
Need apache regex config for rewrite rule
Here is a scenario of what I am trying to do.
Folder A has folders B and C.
Folder B has D, E and index.html.
Folder C has index.html
I declared folder B as my DocumentRoot. Declared an Alias for ...
2
votes
1
answer
300
views
Bitnami Apache rewrite Rewrite Cond and Rule
I would really appreciate some help in rewriting something.
I have moved a site to a sub domain and now the links to that site are not working.
The link before was:
https://www.domainname.com/folder/...
0
votes
1
answer
102
views
htaccess rewrite condition 404 all querystring only on index page
i was trying to protect the main page because on google console my report on a querystring is visible like this example:
https://example.com/?s=something.g
i would like to 404 all querystring only on ...
0
votes
1
answer
104
views
Apache rewrite with GET parameters not working
I have a url: www.example.com/products.php?category=category
that I want to rewrite to www.example.com/products/category
(the category can be either meats, condiments or smokers depending on which ...
1
vote
1
answer
30
views
Problem with htaccess rewrite rule for seo friendly url
After a month of trying, I couldn't solve the problem:
I am trying to redirect this url:
https://www.example.com/news.php?post=hello-world
to this url:
https://www.example.com/news/hello-world
my ...
1
vote
1
answer
42
views
How to mod_rewrite to redirect specific string length?
Here is what i'm trying to do : when someone access my site using a fixed 32 char string 'folder', it will redirect for a specific site passing this string as parameter
For instance :
www.example.com/...
1
vote
1
answer
70
views
How can I change slash (/) to hyphen in .htaccess file
I have only using php and mysql in my website. I faced problem GET URL change slash to hyphen but not get data.
This is my .htaccess file code
RewriteRule ^list/(.*)/(.*)/$ /list.php?name=$1&date=$...
1
vote
1
answer
62
views
Regex: combine 2 rules into 1
i have an .htacces rule. I need to find the first integer after a dot (or not). Here's a good sample of good data that matches and finds the first capturing group:
discography/type
discography/type/
...
0
votes
0
answers
253
views
How to convert a URL to lowercase while serving a page with a query string?
I am trying to forward a URL from example.com/dir/textstring-VARIABLE.html to example.com/dir/textstring-variable.html, while serving the page example.com/dir/textstring.html?var=variable.
The code I ...
0
votes
1
answer
42
views
Creating friendly urls using .htaccess that is located in a subfolder
I have a folder structure like so
root/folder1/folder2/2023/
This works fine if I put the following .htaccess file in my root folder
RewriteEngine On
RewriteRule ^(\d{4})/foo?$ folder1/folder2/$1/foo....
1
vote
1
answer
45
views
Redirect using htaccess using a slash, underscore or dates as separators - friendly urls
This works fine:
https://example.com/2023/not-the-dinner-day
Using the following RewiteRule
RewriteRule ^(\d{4})/not-the-dinner-day/?$ archive/reports/$1/ntdd.php [NC,L]
I want to get this new URL:
...
2
votes
1
answer
368
views
.htaccess remove specific query string part from URL and redirect query string with same value
I want to redirect URLs with a query string to another query string while removing &anyParameterName=anyValue after the first query string in the From URL using .htaccess
&anyParameterName=...
2
votes
2
answers
91
views
htaccess url rewrite with virtual language folders doubles page name as folder in URL
I have a small PHP website with 3 pages. The page content is dynamically translated in Dutch or English (I take the language from the URL)
\index.php
\page-one.php
\page-two.php
I want to achieve the ...
1
vote
2
answers
356
views
Remove %20 from url with a rewrite rule
I have some urls with %20 (encoded space) inside.
I have to remove %20.
So, for example
https://www.example.com/aaaa%20bbbb/page.html
must become
https://www.example.com/aaaabbbb/page.html
I tried ...
0
votes
1
answer
730
views
How to check IF query string exists in Apache
I am trying to check if the query string is not present in the HTTP request then set some headers. I am following this : https://httpd.apache.org/docs/2.4/expr.html
I have tried -
<If "! %{...
1
vote
1
answer
33
views
mod_ewrite + regex to append 0 to query string parameters
I have urls like this one...
https://localhost/index.php?com=liste-cat-lieux&t=41&l=6088
that i need to rewrite like this :
https://localhost/index.php?com=liste-cat-lieux&t=41&l=...
2
votes
1
answer
67
views
redirect all requests starting with 0x to index.html
My website will be like example.com/0xETHEREUMADDRESS.
So i want to redirect all those request starting with 0x to INDEX.HTML and index.html has already the code to the rest of work.
I need .htaccess ...
0
votes
1
answer
146
views
htaccess Rewrite rule for anything after the domain
I've got a one page website that just has a switch that replaces some content with a local town names.
The normal domain.com will go to index.php, but I want anything after the domain to be passed in ...
0
votes
0
answers
310
views
htaccess Replace all special characters in query string
I have a URL like below:
https://example.com/en/search/result?keys=test"><script>alert('helloworld')</script>
I need to replace special characters with their respective URL ...
2
votes
1
answer
203
views
Apache Rewritemap not being read?
I have a simple key value map file which converts olduserid's to new userid's
The objective is to pullup a member profile page from the old site and redirect to tyhe newsite where the member has a new ...
1
vote
1
answer
49
views
Having trouble with some redirect/rewrite codes .. 301 and 410s
Brand new here and totally NOT a coder, so be gentle. The level of understanding I have here is about that of a toddler, so pretend you're talking to a 5 year old and I should be able to keep up.
I'm ...
2
votes
1
answer
63
views
Add part to a URL via htaccess
I have asked another question on here with the premise of limiting download speeds via PHP and I have since come to conclusion that using mod_limitrate was the best solution. so using the following ...
1
vote
1
answer
32
views
.htaccess Rewrite last five directories as GET values
I have the following URL:
https://sub.example.com/economy/billing/payment-check/434/khipu/1000/CLP/1673526088/
I want the last 5 directories to be converted to GET values, to reflect the following URL:...
2
votes
2
answers
129
views
Multiple hyphen handling (URL rewriting) in .htaccess
It gives me URLs like that : http://localhost/service-brussels/ (service is the key and brussels its place). This URL works perfectly.
But, when I type this URL : http://localhost/service-new-york/ it ...
1
vote
1
answer
406
views
Rewrite rule not working properly on Apache 2.2.15
On my local Linux machine I'm running an Apache 2.2.15 server.
I would like to set an .htaccess RewriteRule in order to set a response header whenever a certain URL query string (?print=pdf&...
1
vote
1
answer
52
views
Matching all subdomains except some from list in htaccess
How to mach all subdomain for example.com (ex. 123.example.com, abc.example.com etc.) except subdomains in this list:
main1
main2
main3
This rule in .htaccess would help to change robots.txt to ...
0
votes
2
answers
243
views
How to search and replace url using .htaccess (regex)
Below is the code from my .htaccess file:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{...
2
votes
1
answer
139
views
How To Rewrite Wordpress URL to remove ? parameter
I have the following URL in a wordpress website:
https://www.example.com/previews/mundoflamenco/gitarre/?gname=myname
I would like it to be rewritten like so (so the ?gname= should be hidden):
https:...
1
vote
1
answer
300
views
how do I solve a 404 error from a pretty url?
I'm trying to redirect my content removing the .php extension from all the files using this .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{...
1
vote
1
answer
44
views
Modify code htaccess to accept parameters via URl
Modify code to accept parameters via URl. Rules to redirect URLs to www.site.com/acessorios.php tried are as follows, where .htaccess rules file is present along side with app folder.
RewriteEngine ON
...
1
vote
1
answer
90
views
Regex for htaccess redirect (with exceptions!)
I am looking forward to redirect hundreds of URL belonging to the path https://example.com/fragen/, for example:
https://www.example.com/fragen/amazonerstattungen/
https://www.example.com/fragen/...
3
votes
1
answer
300
views
Url with %20 showing 404 error code, how to fix?
Below are my .htaccess rules, the first rule is for example.com/search-words but showing 404 error code when you reach it like this example.com/search%20words while the second rule example.com/s/...
1
vote
2
answers
507
views
What is the right htaccess code for Php 7.4 redirect?
Can someone please help me redirect the php pages to html (only in the root directory, without subfolders)? I tried dozens of solutions, but I didn't succeed. The code below redirects everywhere (...
1
vote
1
answer
26
views
.htaccess rewrite multiple urls in the same folder
I want to rewrite some URLs but because I'm kind of a .htaccess fresher, I have no idea how to make it myself.
So far I have: example.com/page/AAA0001/?id=78324#78324 now the page is loading from ...
0
votes
1
answer
161
views
Serve cache via apache/htaccess, if file exists, otherwise load data from database
I found this question:
Serve file from cache folder if it exists, otherwise rewrite to "index.php" using .htaccess
and it was useful but i'm not able to write code for my system.
This is ...
0
votes
0
answers
51
views
htaccess 301 Redirect is not working with RewriteRule
I have this code in the site's htaccess file to apply a redirect on old images but it doesn't work.
RewriteRule ^image\.axd$ /wp-content/uploads/upload%1? [L,NC,NE,R=301]
When i type these urls, it ...
1
vote
1
answer
444
views
RewriteRule to match string NOT containing dot (.) only if it also does not contain another specific word
So, I'm trying to have a RegEx at my .htaccess that uses RewriteRule to redirect website.
My idea is to redirect all URLs that are not files, and I used to do it like this:
RewriteRule ^([^\.]+)/?$ ...
1
vote
1
answer
273
views
Redirect using htaccess using a slash or underscore as separators
Ive searched high and low for this scenario but keep running into more simple solutions
for example
RewriteRule ^stays-the-same/[^A-Z]*[A-Z] %1 [R=301,L,NE]
The goal is to see if the url fits either ...
0
votes
1
answer
59
views
htaccess URL rewrites with multiple Regular Expressions
thanks for your time. I thought I knew how to do this but I've tried dozens of permutations and I'm failing.
I want to replace missing images with a placeholder image of the appropriate size. The real ...
1
vote
1
answer
147
views
Redirect rules targeting subdirectories of various levels
I'm trying to write a couple rules that will be dependent on the number of subdirectory levels present in a url. I have one rule that works for part of what I want, and another for the other part, but ...
1
vote
1
answer
210
views
How to remove Query Strings such as date= or author= from url in Wordpress using htaccess
I used following htacces code for removing date= query string from the URL
RewriteCond %{QUERY_STRING} (?:^|&)date=(.*)$
RewriteRule ^paivamaara/(.*)$ /paivamaara/$1?date=%1 [L,R]
its working on ...
0
votes
1
answer
19
views
Remove multiple directories from URL with unknown variables
Trying to build a rewrite rule that would take a URL like this:
website.com/gallery/{WILDCARD}/gallery-name
and convert it to this:
website.com/gallery-name
I've tried this, but it doesn't work:
...
2
votes
1
answer
238
views
.htacces redirect from upper case to lower case, except the last part of the URL
I need to redirect all address in my website from upper case to lower case, except the last part of the URL.
For example, I want to change
www.domain.com/a/B/C/XpTo
To
www.domain.com/a/b/c/XpTo
Only ...
2
votes
2
answers
251
views
How to replace a specific character in regex?
I want to find a / symbol on given text and replace with * symbol.
http://localhost:7070/home/test/mobile:device.testdevice.id1_123.id2_456.id3_ab-c.CONSTANT_formula:map/TreeMap.json
Here the CONSTANT ...
1
vote
2
answers
84
views
How set rule in .htaccess when QUERY ?random_letters_numbers=abracadabra
My site under attack in logs i have random query on main page:
IP - - [DATE] "GET /?random_letters_numbers=abracadabra HTTP/1.1"
How i can block this query only main page and don't block ...
0
votes
0
answers
36
views
htaccess file does not rendering the get arguments properly
Please consider the following code in .htaccess.
AddDefaultCharset UTF-8
ErrorDocument 404 /error_404.php
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
# Set home page
...
1
vote
1
answer
29
views
Apache mod_rewrite regexp
Can anyone tell me the Apache mod_rewrite code for this:
messages/reply/361568/T2kgdHVk%7CbyBiZW0gPyAgOik
My try that gives 404 error:
RewriteCond "%{REQUEST_URI}" messages\/reply\/(\d+)\...