Stack Exchange Network

Stack Exchange network consists of 174 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 ...

2
votes
1answer
19 views

Rewrite rule not taking effect

I need to place a rewrite rule in my .htaccess file so that requests for http://example.com/jbossas/jboss-configuration are redirected to: http://example.com/jboss-server/jboss-configuration So I ...
3
votes
1answer
30 views

Multiple rules to rewrite the url

Why both rules don't work together and how can i fix it? Only the first one works... I think that there's a conflict between the two rules, but i did not found a solution yet ?p= is the querystring i ...
2
votes
1answer
78 views

htaccess 410 url spam hack requests excluding site generated request

Our site was hacked and links to random content where added to the site. We completely removed the hacked site and put a new one in its place. Everything new including images and content, no other ...
1
vote
1answer
146 views

RewriteEngine .htaccess rules end up redirecting to example.net/https:/example.net

I'm starting to learn about the Apache .htaccess and I have some issues in my website... RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} RewriteCond %{...
2
votes
1answer
44 views

Htaccess redirect pages from subfolder to root directory while preserving any query string

I have moved pages in various sub directories to the root directory and want to set up a 301 redirect for each page and keep any query string that might be present. For example: www.example.com/...
4
votes
1answer
68 views

Moved images to another folder - need help with htaccess rewrite rule for png

I had to move my image folder. Before it was example.com/shoplogo/(name*).png now its example.com/shop-logo/(name*).png just stuck with the rewrite rule :-(.
4
votes
1answer
49 views

Need to create a rewrite rule that will check certain characters in a query string variable and redirect it to another page

Need to create a rewrite rule that will check certain characters in a query string variable and redirect it to another page. Example: http://www/prowebmasters.com/index.html?test=123$4/56 I should ...
2
votes
1answer
25 views

.htaccess to redirect domain1 to domain2

I currently have a .htaccess file with the current lines to force HTTPS: RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] My main domain is ...
1
vote
0answers
44 views

Combining password protection and redirects in .htaccess file

I'm a designer who developed a simple site with HTML and CSS. I'm completely new to .htaccess so it's not surprising I'm struggling to get the file to work as I want. Problem 1: I want to password ...
0
votes
1answer
24 views

.htaccess rewrite rules working on Mac Apache 2.2 but not on CentOS Apache 2.4

I've run into an issue when moving from a test server to a production server. I have a set of .htaccess rules in a file in the public_html site root: #Root directory htaccess RewriteEngine On # ...
2
votes
1answer
10 views

How to define RewriteRule to skip parameter in uri

I heve the following rule: RewriteRule ^/shop$ https://www.example.com/category the rule is working as expected with one exception: if in url there are parameter following the shop path, for example:...
1
vote
1answer
219 views

.htaccess redirect dynamic URL (with numeric ID) to remove “track” from the end

It seems to be easy, but I can't figure out how to solve it, nothing worked for me. I have a dynamic URL like: http://www.example.com/user/46/track and I want to redirect from that URL to http://www....
1
vote
0answers
15 views

Disallow URLs made with mod_rewrite in robots.txts [closed]

Here is my robots.txt file: User-agent: * Disallow: /head.php Disallow: /head/ Disallow: /head Disallow: /header.php Disallow: /header/ Disallow: /header Disallow: /footer.php Disallow: /footer/ ...
1
vote
2answers
125 views

WordPress multisite ERR_TOO_MANY_REDIRECTS where the domain name ends up in the path for nonexistent pages

I have a WordPress multisite setup with subdomains. I have pointed five subdomains to it. I have also installed SSL to main domain and the other subdomains. I have written the below Redirect code for ...
1
vote
1answer
137 views

RewriteCond %{HTTPS} !=on is not working even though RewriteCond %{SERVER_PORT} !^443$ works

I have a requirement to check for non HTTPS URLs in htaccess. My understanding is that RewriteCond %{HTTPS} !=on will match all URLs that are not HTTPS. But upon testing, I find RewriteCond %{HTTPS} !...
1
vote
0answers
23 views

Error in SEO Friendly URL [closed]

I have below url structure http://example.com/blog.php?blogURL=user-already-has-more-than-max_user_connections-active-connections and I want to below http://example.com/blog/user-already-has-more-...
3
votes
1answer
34 views

Problem with .htaccess for files having similar kind of names

I have a file with name lang.php and another file in the same folder with same lang_inst.php. The .htaccess am using is: RewriteEngine On Options -Indexes RewriteCond %{REQUEST_FILENAME} !-d ...
1
vote
1answer
54 views

Apache rewrite existing rewritten url [closed]

I know how to create rewrite rules in Apache but what I don't know is how to rewrite a previously rewritten url. This is an old URL /boats-for-sale/fairline-squadron-55/1280 and I need to redirect ...
3
votes
1answer
72 views

HTTPS redirect, exclude script parameters from URL

My goals: 1. http://example.com/page/index.php -> https://example.com/page/ 2. http://example.com/page/ -> https://example.com/page/ 3. http://www.example.com/page/ -> https://example.com/...
2
votes
1answer
39 views

Are these 3 redirect rules equal?

I would like to redirect the non-https and non-www versions my domain to the https and www version of it. I'm a bit confused by the options. Are these redirect rules equal for my purpose? # REDIRECT ...
4
votes
2answers
429 views

How to force ssl and www for a subdomain as an independent domain?

I have own the example.tld . I want to force SSL and https for root-domain and all of its subdomains. I have used below code in .htaccess file of root-domain: RewriteEngine On RewriteCond %{HTTPS} ...
3
votes
1answer
511 views

How to Redirect Pages with Query String?

I want to Redirect as seen below: https://example.com/p1/p2?sort=p.model&order=ASC&page=2 to https://example.com/p3/p4?sort=p.model&order=ASC&page=2 Also, I have this code in my ....
0
votes
1answer
202 views

Remove two subfolders and change plusses to dashes in the URL using .htaccess

I'm in the process of migrating a website from an old CMS to Wordpress. The way that some of the old URLs were: http://www.example.com/tags/tagged/tag/tag+name For Wordpress, I need it to be the ...
2
votes
1answer
35 views

Redirecting from one page to another page on my website causes 404 error after using .htaccess file

Currently I'm working on a PHP blog. Where I have used an .htaccess file to get a clean URL, here is the code: RewriteEngine On RewriteCond %{HTTPS} !=off RewriteCond %{HTTP_HOST} ^example\.com$ ...
2
votes
1answer
269 views

How to redirect all pages of site A, including those with query strings, to homepage of site B

I want to redirect all pages of SiteA to homepage of SiteB. I used this code in SiteA's .htaccess file: <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^(.*)$ https://SiteB.tld/ [...
2
votes
1answer
43 views

unable to move 5million URL from forum/abc/ to forums/abc/

I had a forum with /forum but it has changed to /forums I want to know if there is a single line code which can redirect my old URL to new ones. It is not simple redirection from /forum to /forums The ...
4
votes
1answer
170 views

How to use rewrite rule to create exception rule for https redirection for directory ./well-known

Here is my situation: Server A: support.example.com -> port 80 is forwarded to this server Server B: hr.example.com Both are running apache2. For server B I want to use Let's encrypt. I want to ...
3
votes
1answer
1k views

500 internal server error when trying to implement reverse proxy under Apache. How do I forward the requests to another server without errors?

I want to forward a request from one server to another. Here is my problem: hr.example.com - port 80 - Server A support.example.com - port 80 - Server B All requests on port 80 are forwarded to ...
3
votes
4answers
110 views

Hold my hand through my htaccess http to https redirects

I've been researching the best way to handle my htaccess file in order to switch from http requests to https and I've seen everything from basing requests off server ports, using server name requests ...
1
vote
3answers
84 views

Help with HTACCESS redirection to HTTPS

I have inherited a web app. It's running fine. But it's using HTTP, not HTTPS. This is the .HTACCESS file: Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ ...
1
vote
0answers
65 views

Trouble with .htaccess rewriting .png/.php [closed]

I'm currently creating a "dynamic signature" for a forum or email signature. The php code writes perfectly fine onto an image with the .php page. When trying to access the .png file with the ...
2
votes
1answer
287 views

Return 410 Gone status for all .html files except a single one?

I bet there's at least one trivial solution to this problem, but I've yet to figure any of them out. In a nutshell, what I'm trying to achieve is, informing the search engines that there are no more ....
4
votes
1answer
525 views

How to add force https to htaccess file RewriteRule with _route_=$1

I inherited support for an Opencart 1.5 site which needs to have SSL enabled. I've edited the config.php files in / and admin/ and adding https:// to the URL is working in the browser and links are ...
2
votes
3answers
47 views

Does redirecting http to https using RewriteEngine preserve my site's link equity?

Running an Apache web server, if I use an .htaccess file to redirect all my http:// traffic to https:// using something like RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{...
4
votes
1answer
66 views

How to redirect from https://hi@example.com/x, to just https://example.com/x (htaccess)?

I have a weird problem where for some reason search engines see that I have duplicate URLs, like https://hi@example.com/x and https://example.com/x I'd like the first (i.e. with hi@) to 301 redirect ...
6
votes
1answer
509 views

Rewrite wildcard subdomains in .htaccess to corresponding folders on the main domain while preserving the subdomain

I'm trying to rewrite a subdomain to a folder/file like this: name.example.com -> example.com/profile/name foo.example.com -> example.com/profile/foo xyzzy.example.com -> example.com/profile/xyzzy ...
2
votes
1answer
48 views

What is `wp-cli.yml` for in the public_html folder?

I recently signed up a hosting package, and installed WordPress from the control panel. I noticed there is wp-cli.yml in the web root folder. The file contains: apache_modules: - mod_rewrite Can ...
6
votes
2answers
77 views

Is Checking For mod_write Really Necessary?

Recently I noticed that many people post .htaccess files here with: <IfModule mod_rewrite.c> Sometimes this even appears several times in the file! It obviously checks to see if mod_write is ...
1
vote
0answers
35 views

Redirect requests fro fonts and icons to the main domain from a subdomain based on part of the URL path

I am having trouble loading fonts and icons hosted on main domain from subdomain. Example: I am on sub.domain.loc/some/weird/path/desired/url/resource/to/load.extension and I need to detect that /...
3
votes
1answer
68 views

How to 301 redirect back to a pretty link without creating an infinite loop in .htaccess

I am doing a rewrite from .htaccess file to redirect pretty links to original URLs: RewriteRule ^users/?$ /?status=users [NC,L,QSA] which redirects my SEO/pretty link: example.com/users to the ...
0
votes
1answer
159 views

How to redirect port 80 on server A to 443 server B

I'm wondering how can use my server A to redirect different URL's to the respective server. Here is my setup: Server A: apache 2.4 on ubuntu 16 Server B: apache 2.4 on windows 2012 Port 80 is ...
4
votes
1answer
780 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
380 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
78 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
70 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
867 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
209 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
4k 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
1k 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
118 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/...