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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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 ...

1
vote
1answer
26 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
13 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
43 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
18 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-...
2
votes
1answer
21 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
45 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
58 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
33 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
69 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
72 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
56 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
30 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
32 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
40 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
77 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
306 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
98 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
61 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
42 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
100 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
160 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
44 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
53 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
273 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
34 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 ...
5
votes
2answers
55 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
30 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
51 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
86 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
507 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
327 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
67 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
64 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
489 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
204 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
2k 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
432 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 ...
2
votes
1answer
27 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
350 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
721 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
412 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
278 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
545 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
622 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, ...
3
votes
2answers
3k 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
72 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
210 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
157 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
550 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'...