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.

1
vote
1answer
22 views

.htaccess rule to redirect entire site except for a couple pages is not working

I've been pulling my hair out for a couple of days over an .htaccess issue. I have a list of redirects which are all being done in this format: Redirect 301 /my-page/ https://www.example.com/my-page/ ...
1
vote
1answer
33 views

Redirected too many times when I try to force https for all URLs

I want to redirect all website urls to https. I used the code below to do so. My website is built up using simple PHP. I don't use any opensource framework or CMS. RewriteEngine On RewriteCond %{...
0
votes
1answer
20 views

How to remove subdirectory and index.php from URL with htaccess?

I've got an apache website stored on the server at /var/www/website/ and it's the only one on that server. I'd like to adjust the URL accordingly. How can I make an .htaccess rule that would do this? ...
2
votes
1answer
21 views

Redirecting using rewrite rules from international top level domains to a language subdirectory doesn't change the domain name

I want to change from TLDs to TLD and language code. Right now we have 4 TLDs for our webpage: example.de example.com example.nl example.fr Now I want to change our settings of our CMS (Contao) to ...
1
vote
2answers
52 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 ...
2
votes
3answers
73 views

htaccess redirect all traffic to secure non www version of page

I'm having trouble with my .htaccess redirects. I need to forward all URLs to the non www version of the URL using HTTPS and also forward any non secure URLs to HTTPS too. In both cases I need to ...
1
vote
0answers
42 views

Password protect a website only if it is the dev site [closed]

I am trying to password protect a website only if it is the dev site using .htaccess and .htpasswd I am using Apache 2.4.29 on Ubuntu 18.04 Here is what I have in the .htaccess file <If "%{...
2
votes
1answer
36 views

Removing PHP Extension in sub directory

I use the following rewrite rule to remove the .php extension from my page urls: RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L] This works great in the root directory of my ...
2
votes
1answer
27 views

Order of RewriteRules is affecting the result

This is my current .htaccess: RewriteEngine On RewriteRule ^([\w-]+)/([a-z0-9]+)/([a-z-0-9]+)$ index.php?p=$1&bay=$2&map=$3 [L] RewriteRule ^test/([\w-]+)/(\d+)$ index.php?page=$1&tab=$2 [...
2
votes
1answer
34 views

Apache rewrite to www. unless it is a dev domain

Here is my current rewrite code in my htaccess file: RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] RewriteRule ^ https://www.%1%{...
1
vote
1answer
40 views

How to rewrite specific pages using mod rewrite?

Assuming that my website homepage is https://example.com/test-website/. What I want to do is to add a query string at the end of the homepage URL and on all pages that start with https://example.com/...
1
vote
1answer
62 views

FrontController dosen´t work

i have a example FrontController, its really simple. index.php: if (isset($_GET['page'])) { $requested_page = $_GET['page']; } else { $requested_page = 'home'; } switch($requested_page) { ...
2
votes
1answer
34 views

Can I use a rewrite rule to send all requests to a single file?

Can I make a single regular expression for all my RewriteRules? I'm rewriting everything to a single file and this this acts like a front-controller. My example: RewriteRule ^de/kontakt/anfahrt$ ...
1
vote
0answers
47 views

Apache alias directory only working for index page, sub pages give 404 unless directory name is omitted [SOLVED] [closed]

So I've got this weird problem, I am trying to host a php codeigniter project but I can only access my index page all the other pages give me a 404 error I want it on port 81 so in ports.conf I have ...
0
votes
1answer
56 views

mod rewrite with two parameters and loading folder

I have domain example.com, when someone go to this domain, I need to automatically redirect to example.com/en/ and need /en/ to be a parameter of variable lang. RewriteCond %{REQUEST_FILENAME} !-d ...
1
vote
1answer
51 views

Add Trailing Slash for certain page types

I would like to add a trailing slash for certain static page types like .html, .asp and .pdf. I tried the following code in .htaccess but it is adding a trailing slash to all types of links. # Force ...
1
vote
1answer
60 views

.htaccess rewrite conditions for https:// pre tag subdomains

I need some extra code in my .htaccess file that configures this HTTP request for HTTPS too! <ifmodule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_HOST} ^(.*)\.example\.com RewriteRule ^...
2
votes
1answer
431 views

.htaccess redirect with all parameters

I have a simple rule in the .htaccess file, to redirect all requests to inwork.php: RewriteRule .* php/inwork.php?refpage=%{REQUEST_URI} [L] But all parameters are missing. For the request http://...
3
votes
2answers
30 views

Mod Rewrite proxy to different backend hosts

I have a virtual host with multiple ServerAlias host1.example.com host02.example.com etc. I match the same pattern and based on ServerAlias I want to proxy them to different backend hosts. What I ...
1
vote
1answer
33 views

How is the mapping done from …/script.php?one,1 to …/script/one/2?

There is a PHP script which evaluates one or two parameters via QUERY_STRING. This script should process the parameters via QUERY_PATH. The PHP file type should be omitted. Request of the form https:/...
2
votes
1answer
31 views

Problem with [R=301]

Some of my RewriteRules don't work if i put the [R=301]. why this don't work? RewriteRule ^sitemap\.xml$ sitemap.php [R=301,L] It shows a Forbidden error when i try to access the URL https://example....
2
votes
1answer
32 views

Rewriterule redirects to URL and shows different URL?

I've a website hosted on an Apache server which hosts other domains. Therefore, I can't access the Apache configuration. On our website, I've several domains. For one of them (domain example.com), I'...
2
votes
1answer
35 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
53 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
186 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
287 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
685 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
304 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
67 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
38 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
56 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
44 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
14 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
369 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
21 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
127 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
465 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
24 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
39 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
55 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
98 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
40 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
2k 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
1k 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
271 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
40 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
508 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
47 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
357 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
3k 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 ...