Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

4
votes
1answer
970 views

RewriteRule doesn't work for a CSS file and a document when a RewriteCondition is added to test if a name value parameter is in the query string

I'm trying to change the DocumentRoot to subfolder through .htaccess. This works well... RewriteCond %{REQUEST_URI} !subfolder/ RewriteRule ^(.*)$ /subfolder/$1 ...however, I only want to do this ...
2
votes
0answers
391 views

How to use .htaccess rewrite rules to remove .php and folders from URLs?

I'm trying to simplify the URLs using rewrite condtions and rules on my local WAMP website. For example I would like to have /ProjetSyntheseFAC/mammiferes instead of /ProjetSyntheseFAC/pages/animaux/...
2
votes
2answers
83 views

.htaccess RewriteRule leading to unexpected page

I'm trying to do a simple invisible redirection with .htaccess which almost work. I'd like my main domain name example.com to access the content of the folder example.com/V8/ but keeping only the ...
5
votes
1answer
84 views

Wrong URL Requested But I know what they meant - 404 vs canonical vs 301 redirect

I'm using mod_rewrite to process variables in the URL. For many of my URLs the final portion of the string doesn't matter because I'm not using it. For instance: /review/company-25/jb-hunt I'm only ...
2
votes
3answers
1k views

HTTP to HTTPS redirect: How not to create an infinite loop

I have a WordPress install on a subdomain: https://blog.example.com To enforce SSL I have the following redirects in my .htaccess: <IfModule mod_rewrite.c> RewriteEngine On # BEGIN FORCE ...
2
votes
1answer
224 views

Simple .htaccess language question (redirection)

I do not know the language of .htaccess, thus the newbie question. I have this code: RewriteEngine On RewriteCond %{QUERY_STRING} ^m=1$ RewriteRule (.*) /$1? [R=301,L] It redirects any urls that ...
2
votes
2answers
5k views

How to remove subdirectory folders from the url using htaccess

I am trying to remove the sub-folders from my site URL. Below is the structure of my folders. I am not sure where to place my .htaccess file and what to have written in it: mysiteroot ...
1
vote
1answer
2k views

How do I prevent a rewrite rule from executing for just one subdomain?

In the root level .htaccess I have added a condition to rewrite HTTP requests as HTTPS: RewriteEngine On RewriteCond %{HTTPS} !on RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} This applies to ...
3
votes
1answer
146 views

Redirect 301 for Apache Sub directory and query string combination

I am getting 404 errors in Google Search Console for URLs like the following: http://www.example.com/newsite12121212121212/eg/st_tour/perma/ http://www.example.com/newsite12121212121212/eg/...
2
votes
1answer
42 views

I couldn't create .htaccess redirect

From /etiket/(any page) to /konu/(any page). How can I do it? In .htaccess file. I searched and applied it but couldn't. # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase ...
3
votes
1answer
636 views

How to redirect all (www).example.(com/net/org) to https://example.com

How do I setup any URL/URI for http(s)://(www).example.(com/net/org)/somepath to end up at the corresponding: https://example.com/somepath I'm guessing that the solution (if there is one), will ...
1
vote
1answer
1k views

Apache Reverse Proxy Rewrite Remote_User

Running httpd 2.4.6 on CentOS 7 as a reverse proxy for Splunk with SSO. This works with no proxying: RewriteCond %{LA-U:REMOTE_USER} "user" [NC] RewriteRule ^.*$ - [F,L] The above does NOT work ...
2
votes
2answers
764 views

Redirect to WWW with HTTPS optimization

I want to redirect all my website pages to https and www. In order to do that I'm using the rules below and it's working fine. # Rewrite to WWW with HTTPS RewriteCond %{HTTPS} off # First rewrite to ...
2
votes
1answer
354 views

Redirect subdomain to their folders without double slash and such that parameters get sent through login

I have a wildcard DNS setup on my server, something like .example.com. In my root folder there are some sites, so what I need is to have something like this: test.example.com should use test directory ...
0
votes
2answers
915 views

Apache .htaccess: Is it possible to write an if condition for a cookie value check?

I want to write an if condition in an .htaccess file to check whether a cookie value is set. Example code: <If "%{HTTP_COOKIE} == 'cookiename and value'"> ... </If>
3
votes
1answer
955 views

URL-path with encoded question mark results in incorrect redirect when copied to target URL

I have a simple RewriteRule, appending a string to some URLs: RewriteRule ^labels/([^/]+)/?$ /labels/$1/releases/ [R=301,L,NC] The links are database driven, and this is working very well. Well, ...
4
votes
2answers
6k views

Redirect from URL with parameters to SEO friendly URL in .htaccess

I have category page with this structure example.com/Category.php?Category_Id=10&Category_Title=some-text i want to write htaccess rules to redirect from example.com/Category.php?Category_Id=...
1
vote
1answer
80 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
366 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/...
3
votes
1answer
255 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
1k 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
275 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
2k 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
408 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
295 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
157 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....
6
votes
1answer
2k 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
127 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
1k 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
621 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
4k 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
561 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=...
3
votes
1answer
222 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 ...
4
votes
1answer
2k 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
540 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
403 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
141 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} ^/...
3
votes
1answer
468 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
4k 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
258 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 ...
4
votes
1answer
4k 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
128 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 ...
4
votes
1answer
75 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
312 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
414 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 wrinkle here is that I only want particular Mobile Users accessing ...
1
vote
1answer
40 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). ...