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
1
vote
1answer
89 views

Use .htaccess to make pretty URLs that expand abbreviation codes

Yes, I know, there are tons of questions like this, but I can't find one which solves my problem so at cost of receiving downvotes I'm going to ask this again. Even a duplicate link may help me. This ...
3
votes
2answers
475 views

Send “410 Gone” response for URLs that are a “c” or “g” followed by digits

Is there anything i can use in my htaccess to send 410 code to all the links but not some links ? Example: I would like to 410 this urls (List is about 40k links) www.example.com/c1 www.example.com/...
2
votes
1answer
279 views

RewriteEngine On showing Apache test page

I have centos 7 and I need to put this .htaccess file inside one of my directories (www/html/forum) in order to display friendly URLs so instead of looking like example.com/index.php?user=222 it would ...
4
votes
2answers
2k views

The question mark ('?') in URLs is preventing htaccess code from blocking them

I want to block someone using this dynamic URL: REQUEST_URI = /%24%24%24%26%3f%26%3f%24%24%24?cmd=get_file&arg=images/wslogo_block_page.png&sid=3257F1B3D8C5432EB676D55891B428ED164A3561 There'...
2
votes
1answer
338 views

.htaccess errordocument 404 for .htm and .html

My .htaccess is displayed below. It catches example.com/abcnonsense and sends it to my error page - 404error.htm. But fails to catch example.com/abcnonsense.htm or example.com/abcnonsense.html. In ...
3
votes
2answers
3k views

Redirecting directory without slash to directory with slash and https

I'm trying to redirect address: http://example.com/blog to address: https://example.com/blog/ Take into account that, I'm trying to redirect from NO HTTPS to HTTPS. So far, I achieved the desired ...
2
votes
1answer
2k views

(nginx rewrite) add word on dynamic URL ending | word is repeated multiple in URL

I'm really confused by the Nginx rewrite rules. I have searched and found a lot of threads for rewrite rules but I don't get the required result... I have this form of a link: http://example.com/...
5
votes
2answers
483 views

Properly redirect a site to WWW and HTTPS

I recently found out a problem in .htaccess file in my website. When I started the site I did a 301 redirect to redirect all non-www and http request to www with https. I added this lines of code and ...
4
votes
1answer
383 views

.htaccess to WWW And/Or HTTPS

On my site I want to do these redirects: http[s]://example.com => https://www.example.com https://www.example.com => No Redirect http://sub.example.com => https://sub.example.com http[s]://www.sub....
2
votes
1answer
172 views

.htaccess and permanent redirection with a special condition

I have a WordPress website hosted on Bluehost which contains the following URL pattern: http://www.example.com/2017/01/30/sample-post/ I wanted to permanent redirect it to use this: http://www....
5
votes
1answer
3k views

rewrite url - remove trailing / if any and add .php

I have a simple question, yet I've found no posts that answer my question. I need an htaccess file that rewrites the urls so that it removes the ending / if any, and adds .php no matter what the ...
5
votes
1answer
69 views

.htaccess several domains to point to different locations

I have a main domain in a hosting plan and then several domains "parked" in the same hosting plan: main_domain.com domain1.com domain2.com domain3.com I need each of those domains to be MASK-...
1
vote
0answers
140 views

Create unique IDs between URL with nginx [closed]

I searched and tried nearly two weeks but don't get any useful result, so I'm trying my luck here before I get crazy: Every existing domain should get an unique ID right after the domain. The ID ...
5
votes
1answer
2k views

WordPress HTTP to HTTPS without trailing slash results in double redirect

I have noticed that one of my WordPress powered sites is experiencing double redirects when a user or bot attempts to visit a URL without HTTPS and a trailing slash. In short: http://example.com/...
1
vote
1answer
954 views

Mod Rewrite: HTACCESS How to rewrite a single URL to another?

I have read through a ton of other similar questions and have tried too many combinations of code, but nothing works. I just need to add a single rewrite (not redirect) to my htaccess: Here is the ...
2
votes
1answer
7k views

RewriteCond to not rewrite a specific URI not working

I am working with a URL shortener (YOURLS) and I'm trying to have a certain page not directed to the link processing script. Here's the original .htaccess: # BEGIN YOURLS <IfModule mod_rewrite.c&...
2
votes
1answer
671 views

mod_rewrite part of the query string

I have a situation with opencart where I need to rewrite only the "route" leaving other query strings as it is. Example: http://www.example.com/?route=module/ext/products&category_id=15&sort=...
2
votes
1answer
228 views

How to redirect multiple new domains back to their primary domain without negatively affecting SEO/Rankings or anything else?

I've searched Google high and low. There are many answers to this question. I even asked another question similar to this one however it lacked specificity. Something this question will not lack. I ...
3
votes
1answer
3k views

Rewrite subdomain to folder keeping the URL unchanged

I'm on a cheap shared hosting with Apache and I'm trying to do the following rewrite with .htaccess: http://anything.example.com/par1/par2 => http://example.com/anything/index.php?a=par1&b=par2 ...
2
votes
1answer
771 views

apache rewrite rule set for “whitelist or catchall” in .htaccess

On the dev version of a LAMP site (Apache 2.4 on Debian 8.5), my Apache rewrite rules implement a "whitelist then catch-all" concept. Specifically, images from images/, stylesheets from css/, ...
1
vote
1answer
637 views

Rewrite URL with multiple queries

This article describes how to direct incoming traffic coming from "fake" URLs of this type: http://www.example.com/seo-sample/article-install-apache-on-linux.php to a PHP file that "really" uses ...
1
vote
1answer
255 views

How to eliminate space on .htaccess

Somehow a space was introduced in some of my URL like: /marques-voiture/Ford /marques-voiture/ Ford I attempted to correct that with the following rule on .htaccess RewriteCond %{REQUEST_URI} ^/...
2
votes
1answer
607 views

Htaccess results in an Error on http to https change in proxy

I am having an issue trying to change my rewrite rule to use https. Before change, I had the following: RewriteEngine On RewriteBase / RewriteRule ^api/(.*)$ http://example.com/api/$1 [L,P] Which ...
6
votes
2answers
6k views

Have Apache show 404 at missing page URL instead of redirecting to error page URL

Assuming non-existent-page.html does not exist, and the user is trying to access that page and triggered a 404 error. Can i show the requested page URL: http://www.example.com/non-existent-page.html ...
0
votes
1answer
1k views

Firefox “The page isn’t redirecting properly” for a Wiki (all other Pages and UAs are OK) [closed]

We are having trouble with a website for a free and open source project. The website and its three components are as follows. Its running on a CenOS 7 VM hosted by someone else (PaaS). site: www....
3
votes
1answer
294 views

Using mod_rewrite to access httpOnly cookie?

I have Apache running as a secure proxy (Port 443) between an HTTPS site and the rest of the world. This site is setting a secure, httpOnly cookie. The cookie when seen in a trace shows up in a ...
5
votes
1answer
6k views

.htaccess Direct all requests to Public dir when using framework etc

I using this .htaccess code to direct all requests to Public directory: <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ public/$1 [L] </IfModule> ...
2
votes
1answer
165 views

Routing URLs .htaccess file problem

When I click any link on my website it will show only the home page. http://example.com/article-rewriter When I add ?route=, the URL is correct: http://example.com/?route=article-rewriter/ How can ...
3
votes
1answer
76 views

Why does apache redirect to www without RewriteRule

So I have a webserver running on Apache, with a few virtual hosts. I want to default to https and hence I have a rewrite rule. <VirtualHost *:80> ServerName example.com ...
2
votes
1answer
1k views

How to remove trailing slashes from URL with .htaccess in localhost?

Here is my localhost folder structure: •www (wamphost folder) •example.com (folder) •index.php With the current the URL results: localhost/example.com/ The URL I would like is: ...
2
votes
1answer
370 views

Htaccess w/ Wordpress: rewrite specific path to root domain but keep full path

I want http://example.com/foo-bar to display the webpage from http://example.com/ but retain /foo-bar in the address bar. I know it appears as a duplicate of many RewriteRule questions asked here, ...
5
votes
1answer
784 views

Using mod_rewrite to check for existence of a cookie

I have an internal website at my company that I'd like to allow outside access to via a reverse proxy with an Apache Server. The difficulty here is that I only want particular mobile users accessing ...
1
vote
1answer
41 views

Redirecting all traffic to a script

I am on Centos 6.5 with Apache2 and Perl 5.23. I need to pass all traffic to the single perl script, check this request in a database, and show needed content (have both static and dynamic content). ...
2
votes
1answer
311 views

Crafting a regex for mod_rewrite with more than nine parameters

Say for example, I have a URL in this format: http://example.com/(mobile-or-desktop-flag)/(major-venue-category)/(smaller-venue-category)/(venue-name)/(month)-(day)-(year)/(picture-number)/(user-...
3
votes
1answer
244 views

Can Apache serve resources recursively if there's a 404 in the current directory?

Is there a possibility to serve resources hosted with Apache recursively across the directory hierarchy, using mod_rewrite or the like? Example#1: A server document css/php/html/... refers to the ...
2
votes
1answer
105 views

combined 301 redirects not working

I made some changes to the files on a website and now Search Console is showing me 404 errors for some URLs. The normal setup, which works fine is like this: the user-friendly URL mywebsite.com/...
2
votes
1answer
198 views

How to regex a url to redirect user

Using the regex and the .htaccess file, I want to redirect users to a certain URL. I want to redirect: http://www.example.com/* but not http://www.example.com/CDadmin/* I have tried the following: ...
1
vote
1answer
124 views

RewriteRule RewriteCond

These codes dont work together... How can I integrate both codes? # Block#1 RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^search/(.+?)/(\d+)/?$ /search.php?q=$1&p=$2 [L,QSA,NC] RewriteCond %{...
2
votes
1answer
50 views

Apache 2 mod_rewrite Inconsistent Results

My former university, SPSU, was "consolidated" into Kennesaw State University. I used to have the domain bbrown.spsu.edu. As a temporary fix, bbrown.kennesaw.edu was set up by University IT. ...
2
votes
0answers
27 views

Passthrough in Virtualhost not preserving the previous URL

I have a RewriteRule written at Apache to redirect to TOMCAT. Passthrough [PT] doesn't seems to work and Getting Bad Request. Same configuration works with [P], but I don't want tomcat PORT to be ...
2
votes
1answer
1k views

htaccess 301 redirect for second level sub directory

I have a directory website with the following URL structure. http://mywebsite.com/information/business-name/ http://mywebsite.com/information/business-name/product-names/ http://mywebsite.com/...
3
votes
2answers
506 views

Redirecting specific URL from HTTPS to HTTP

Long time lurker, first time caller... I have a backend like admin.mysite.com which is able to use HTTPS (has a certificate installed, etc) - but that admin portal is a CMS backend for a number of ...
4
votes
1answer
53 views

.htaccess rule fails when including $ at end

The Basic Situation We have a server. It has some static files, some simple, "flat" .php and .html pages, but it also has a WordPress install at the document root, meaning that visiting / takes the ...
1
vote
1answer
301 views

How to add http:// prefix to subdomain redirect in htaccess

I am rewriting a subdomain URL with a query (cart.example.net/ProductDetail.jsp?LISTID=7C0400-1101763508) to a www subdomain (www.example.net/product-category/product). The problem I am facing is the ...
3
votes
1answer
400 views

Apache mod_rewrite problem with adding a query string on an internal rewrite

I need to replace /xyz with /index.html?dh=xyz. I use the following config in httpd.conf: RewriteCond %{QUERY_STRING} "!dh" RewriteRule "^/(.*)$" "/index.html?dh=$1" [R] This works perfectly if [R] ...
2
votes
0answers
573 views

Strange HTTP:Accept-Language behavior instead of Browser Language Detect [closed]

My qTranslate-X (v3.4.6.4) WordPress (v4.4.2) plugin can't "Detect the language of the browser and redirect accordingly.", so i needed to do a hack by .htaccess. Following solution found in Drupal's ....
3
votes
3answers
1k views

Redirect $.html to $/ mod_rewrite rule clash

I have already remapped URL's from for example /sub/test/ to test.html but I also want to redirect /sub/test.html to /sub/test/ but here seems to be a clash between the rules. .htaccess files is in ...
2
votes
1answer
353 views

.htaccess mod rewrite sub directories redirect loop

I am trying to setup a sub-directory with individual .htaccess. I want to redirect .html files to url without extensions and also add a trailing slash and redirect all non-slashed urls there. Here's ...
3
votes
2answers
78 views

Is a real http to htttps rewrite possible or is this always going to be a redirect?

I noticed that there are some articles on the Internet that talk about using the apache mod_rewrite module to rewrite a client to server http connection to https. But rewrite does all the changes ...
2
votes
1answer
1k views

How do I redirect /search/ to /?s=

I have a typical Wordpress site, with a typical Search page set up which uses the typical GET format <form id="searchform" action="http://example.com" method="get"> <input id="s" ...