Questions tagged [mod-rewrite]

mod_rewrite is a URL rewriting module for the Apache web server. It is commonly used for so-called "pretty" URLs because of its ability to redirect on the server side (transparent to clients and their browsers), but also provides the power and flexibility to perform various request handling tasks beyond simple substitutions.

Filter by
Sorted by
Tagged with
3 votes
2 answers
2k views

Redirect loop in .htaccess when removing trailing slash

I have the following .htaccess file: AddDefaultCharset utf-8 RewriteEngine on Options +SymLinksIfOwnerMatch RewriteBase / # redirect all www-requests to no-www # - RewriteCond %{HTTP_HOST} ^www\....
0 votes
1 answer
29 views

SSL sertificate crushes with AllowOverride all

When I changed AllowOverride "none" to "all" in httpd.conf - my .htaccess file started to work, but my SSL dont want to work with that... <Directory "/var/www/html">...
2 votes
1 answer
119 views

.htaccess rewrite does not work with adwords gclid passed to the final url

Have a problem with traffic coming from Google Ads. A have a redirect roll that redirects https://example.com/some-words-words-aktivitet/ to https://example.com/index.php?mobile=1 (RewriteRule ^some-...
3 votes
1 answer
112 views

Redirect double-slash "//" URLs using a rewrite rule in the .htaccess file

Google Search Console is giving me the Duplicate without user-selected canonical error for URLs that contain an unnecessary double slash // in them, like: https://university.edu/~user//dir/ To avoid ...
1 vote
1 answer
160 views

Redirection of Spams hacked page 404 to 410 .htacess

My website has been spammed by hackers for maybe 1 year. So now I have to update everything I think. And it seems that the page targetted by spammers is going to 404. My question : I tested this ...
9 votes
2 answers
7k views

AH10411: Rewritten query string contains control characters or spaces

How to reproduce the error: -- A space in my URL will trigger the error. Observation of the error: -- It seems to happen suddenly since around 3/10. ---- I did not upgrade my Apache version, but it ...
-1 votes
1 answer
89 views

htaccess and redirects

I'm wanting my URL to resolve to https://example.com if the visitor is typing in the URL with http://www or http:// or https://www Right now I have a redirect in my htaccess and it works but I get ...
0 votes
0 answers
180 views

Can't Find a Solution for Removing Trailing Slash at End of Directory URL

Please help me get my URL folders to point to index.php without a slash at the end. I tried this guide, but all I get is a URL with the slash at the end of it. The computer displays the right page, ...
2 votes
1 answer
50 views

Odd slash added at start of file folder in Apache rewrite

I'm working with an Apache rewrite statement that reads: RewriteRule ^((?!%{HTTP_HOST}).*)$ ${US_ROOTF_WWW}/www.%{HTTP_HOST}%{REQUEST_URI} [L,E=PROJECT_PREPENDED:1] The value of {US_ROOTF_WWW} is C:/...
3 votes
2 answers
9k views

What does ^(.*) mean in a rewrite rule, is there a simpler alternative?

I have just copy and pasted a rewrite rule for a redirect from some website. It contains: ^(.*) I want to know what it means. Why is it so complicated? Can it be simplified? The whole .htaccess ...
0 votes
1 answer
224 views

How to use mod-rewrite for SEO friendly get params?

At present the webpage accepts get params like this https://TripTale.in /details.php?id=AlphaNumericKeys Which I want to make it look like https://TripTale.in /details/someTexts/AlphaNumericKeys ...
1 vote
1 answer
255 views

htaccess redirect with negated conditions

Simple redirect in .htaccess works: #Redirect 302 / https://domain.toberedirected.com But the conditional one doesn't. I want that if the remote user IP address is in the list then ignore the ...
1 vote
5 answers
25k views

Remove folder name from rewritten URLs

Consider this URL: http://example.com/gallery/20141111-some-title In this URL I want to hide gallery/: http://example.com/20141111-some-title How can I achieve this using mod_rewrite? I used ...
2 votes
0 answers
51 views

Redirect the bare domain to a subdomain and still make the bare domain appear to users to fix a CSP error that occurs when using the bare domain?

I'd be grateful for some guidance with URL redirects in the .htaccess files as I'm not sure how to handle (though I hope it's straightforward). I've installed a site into a subdomain, let's call it ...
8 votes
1 answer
3k views

RewriteRule started returning 403 Forbidden error

I have a website that uses a set of quite simple RewriteRules of the format: RewriteRule ^p/(.*)$ /product.php?$1 [L] All was working well and still is working perfectly fine on localhost. For some ...
0 votes
1 answer
186 views

Remove sub folder name from URL

http://example.com/portal/reports/data.php?id=2 In this URL I want to hide portal folder in the url/: http://example.com/reports/data.php?id=2 How can I achieve this using mod_rewrite? I used online ...
2 votes
1 answer
154 views

.htaccess redirect php WHMCS cart ID

For WHMCS I am trying to redirect products to another ID and subdomain. How can I create a .htaccess that will redirect https://www.example.com/clients/cart.php?a=add&pid=17 to https://clients....
2 votes
1 answer
609 views

Problem with Apache rewrite with wildcard domains

I have a PHP app on Apache2 that is supposed to treat subdomains on the code level. My goal is to redirect any wildcard subdomain to the main domain's index.php. I do not use .htaccess. I searched ...
1 vote
1 answer
91 views

Website not working due to htaccess

My website was fine (apologies in advance for not being a webmaster or developer) until SSL was enforced through hosting platform - a 500 error code/page showing internal server error. Spoke to ...
4 votes
1 answer
242 views

Handling # uri fragments as regular requests

So I have a one-page website with multiple sections and IDs. Right now, in the nav, I have it going to #about to jump them down to a section with ID=about But I want the user to be able to go to ...
2 votes
1 answer
579 views

Why is this .htaccess evaluating to 302 redirect instead of internal rewrite?

As an example, I was expecting this https://example.software/credits to evaluate to an internal rewrite https://example.software?mode=credits Why is it showing up on the browser url-bar as a 302 ...
2 votes
1 answer
443 views

How to rewrite a request to different files based on the domain name in ".htaccess"?

I run the website https://www.1.example. The contents of my .htaccess file are as follows: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ \...
4 votes
1 answer
753 views

Modify rewrite rule to match ONLY directories, NOT directories AND files

I have the following rule in my .htaccess file: RewriteRule ^[^/].*/(dir1|dir2|dir3)(.+) $1$2 [QSA] It works great for the directories except sometimes it conflicts with files. How can I modify this ...
6 votes
1 answer
388 views

Htaccess Hotlinking Prevention: Exclude a specific image from rule

I have a working hotlinking prevention in the .htaccess. Everything works fine. However, I use an image of my website in email signature. After the hotlinking prevention, this image is now displayed ...
3 votes
0 answers
241 views

Automatic display of WebP images instead of JPG images via Htaccess

I use Wordpress, the plugin "EWWW Image Optimizer" creates from JPG images automatically also WebP versions (example: From the image image.jpg is also an image image.jpg.webp created). The ...
1 vote
1 answer
48 views

Old alternative domain names -- is it actually worth setting DNS to resolve at the website?

Someone noticed a problem with a site I manage in that somewhere all the old alternative domain names which we keep paying for were in the Google search results. Some problem had come up somewhere ...
0 votes
0 answers
138 views

Run .htaccess rule to remove trailing slash only if such a file exists

I have the following .htaccess rule but I would only like it to run it if a file exists without the removed trailing slash: RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R=301] I use ...
2 votes
1 answer
3k views

URL rewrite issue with CakePHP

I am using CakePHP framework 2.2.2 I want to create personalize URL for user if user enter username=pragnesh then they can access my site like http://pragnesh.example.com same as in blinksale.com My ...
1 vote
1 answer
745 views

.htaccess rewrite stops working for JavaScript files after moving server

We recently moved an old PHP Project from a server using httpd to our regular production servers running Apache2. In this project we have some rewrite rules that map requests either to our index.php ...
3 votes
1 answer
256 views

Standard WordPress mod_rewrite rules interacting with one of my own rules are causing all requests for a certain page to be sent to the homepage

I have WordPress 3.5.1 installed on Ubuntu 12.04 LTS. I'm running Apache 2.2.22. I can't share the domain that I'm working on, and must sanitize any config files and log outputs. While the website is ...
2 votes
1 answer
2k views

Redirecting one page to HTTPS, and all others back to HTTP isn't working as expected

I have WordPress 3.5.1 installed on Ubuntu 12.04 LTS. I'm running Apache 2.2.22. NOTE: I can't share the domain that I'm working on, and must sanitize any config files. While the website is public, ...
2 votes
1 answer
353 views

Non-ascii characters in RewriteRule :alpha:

I have RewriteRule ^([[:alpha:]]+)$ do-something.php?parameter=$1 and it works for URLs like .../Virtanen. For .../Mähönen I can use ([ÄÖäö[:alpha:]]+, but that of course fails for, say, .../Vadén. ...
1 vote
1 answer
856 views

Rewrite three URL directories to corresponding PHP files and pass subdirectory as a parameter

I want to convert the following https://example.com/download-file/xyz https://example.com/download-code/abc https://example.com/developer/mno to https://example.com/download-file?name=xyz https://...
3 votes
1 answer
240 views

Mod rewrite doesn't work when I added multiple domains

I have Redhat Linux server and I was using /var/www/html to display my site. By using the following directive rewrite mod was working fine. <IfModule mod_rewrite.c> # Enable mod_rewrite engine ...
2 votes
1 answer
764 views

custom 404 page not work Apache/2.4.51 if missing is in a virtual subdirectory (Debian)

this is my first question here, I hope to find a solution. I have a problem with page 404 when the missing page is in a sub "virtual" directory, is used to pass a value to php, in ...
24 votes
2 answers
23k views

htaccess execution order and priority

Can anyone explain to me in what order apache executes .htaccess files residing in different levels of the same path and how the rewrite rules therein are prioritized? For example, why doesn't the ...
1 vote
1 answer
461 views

Redirect AMP Parameter To Its Permalink caught in Redirect loop

I have the same issue as mentioned on Redirect AMP Parameter To Its Permalink, the solution given by Mrwhite solved my problem and everything went fine # Redirect old "amp" URLs back to ...
2 votes
1 answer
514 views

Redirect AMP Parameter To Its Permalink

I have a similar situation as described in Handle "amp" in URLs from a now removed WordPress plugin the difference is I don't use custom post permalink /%postname%.html but just /%postname%...
4 votes
1 answer
15k views

How to do 301 redirect for complete URL?

I have a lot of URL, which can't be redirected, or, better, rewrited with mod_rewrite in .htaccess, so instead rewriting, I have created 301 redirects manually. It isn't too much records, about 40 ...
7 votes
2 answers
22k views

how to rewrite %20 in .htaccess

I need to perform an equivalent rewrite to: RewriteRule ^/this%20file.pdf http://www.example.com/ How do I handle the %20? I have tried RewriteRule ^/this\%20file.pdf http://www.example.com/ and ...
4 votes
1 answer
562 views

Why rewrite to index.php is not working on a wordpress site?

So my rewriterule is like RewriteRule ^test$ index.php [L] I tested it on https://htaccess.madewithlove.com?share=b0a9904b-1ec4-49cd-917c-36426ff6150a it works fine. I also tested it on live Joomla ...
3 votes
1 answer
502 views

Where to place 301 redirects in my Wordpress htaccess file?

I have about 25 301 redirects in my WordPress .htaccess file, that looks like this: Redirect 301 /store/index.html https://www.example.com/store-home/ At the moment they are at the bottom of my ....
3 votes
0 answers
71 views

.htaccess not redirecting me to correct place

I have a website which opens to /resources/Installer/index.php but the path I need it to open to is /Installer/index.php. I have asked my webhost to help but they have said they cannot help. I have ...
2 votes
1 answer
77 views

Create a virtual index file to prevent 403s

I'd like to serve (httpd) either 404s or 200s instead of 403s. I found a way to redirect and change 403s so they become 404s but I'm not trying to replace 403s altogether but rather where they are ...
3 votes
1 answer
537 views

How are slashes added between htaccess mod_rewrite variables

I was looking at two different variants of redirects: RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301] RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] And noticed that in the first ...
5 votes
4 answers
5k views

How to write a generic .htaccess file rule, regarding RewriteBase

The following rule in my .htaccess works just fine for routing calls to index.php: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [QSA,L] However, this does not ...
2 votes
1 answer
150 views

How do I match string in URL path at any level to specific file using mod_rewrite

It's likely that I missed the answer already because I'm not even sure how to phrase this, but here it goes... I'm attempting to create a healthcheck virtual--something "file", maybe, so ...
7 votes
2 answers
1k views

In .htaccess files, is there any difference at all between “!=on” and “off”

I’m trying to better understand Apache’s use of a binary attribute. In an .htaccess file with the code # Check if HTTPS is 𝗻𝗼𝘁 𝗼𝗻 RewriteCond %{HTTPS} !=on Is there more processing occurring&#...
6 votes
1 answer
27k views

Apache .htaccess mod_rewrite: use of [NC]

I see tons of .htaccess examples containing the [NC] flag (NoCase = case-insensitive) For example the famous h5bp page uses the [NC] flag a lot: https://github.com/h5bp/server-configs-apache/blob/...
2 votes
2 answers
314 views

Apache maintenance page htaccess without being overriden by subfolder

I want to perform a maintenance on my website, so wrote an htaccess (I do not own the server) to redirect users to a specific page. <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{...

1
2 3 4 5
13