We’re rewarding the question askers & reputations are being recalculated! Read more.

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
2
votes
0answers
21 views

Why do my analytics report that index.php appears in URLs despite friendly URL rewrite rules?

On a website i use mod_rewrite and PHP to create clean URL's. My .htaccess (summary) will look like that shown below: RewriteEngine On #oude pagina's RewriteRule ^nl/links/(.*)/index.php$ /...
2
votes
1answer
55 views

.htaccess, redirect all to bye.php, even with more slashes, with exception

I need, in .htaccess, redirect all behind domain, but even with more slashes and with slash or no slash at the end, but with one exception. For example example.com/all/sites/should/redirect/to/one/...
2
votes
0answers
29 views

After rewriting RoundCube URLs, CSS, JS, and image resource links are broken

What I'd like to do is that I want to make nice URLs for my roundcube pages with .htaccess. For example: RewriteRule ^latest/$ index.php?_action=news&type=latest [NC,L] If I go to this ...
1
vote
2answers
19 views

Why doesn't my .htaccess file redirect my old WordPress permalink structure?

About 9 months ago i changed my permalink structure in WordPress from the domain.com/year/month/article-name format to the domain.com/article-name one. I hired someone to do the rewrite rules for ...
2
votes
3answers
137 views

Using htaccess to force HTTPS doesn't work

NEW EDIT 28/oct/19 → I edited the .htaccess file as you said AddHandler x-mapp-php5.5 .php # HTTP to HTTPS redirect RewriteCond %{SERVER_PORT} 80 RewriteRule (.*) https://www.bebechan.net/$1 [R=301,...
2
votes
1answer
168 views

Forcing all requests to HTTPS vs not forcing all requests

I'm not new to cleaning up mixed content errors after switching from http to https and I'm not new to working with the htaccess file but I am new to actually implementing the rules for http to https ...
4
votes
1answer
53 views

Problem opening files with encoded filenames

I have a website where users can upload files, if they upload a file with a special character in the filename, the filename will be encoded (for example: iordănescu.pdf will become iord%C4%83nescu.pdf)...
2
votes
1answer
29 views

Deny Multiple Spammy Domains via htaccess

<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_REFERER} ^http(s)?://([^.]+\.)*tumblr\.com [NC,OR] RewriteCond %{HTTP_REFERER} ^http(s)?://([^.]+\.)*nometoqueslashelveticas\.com [NC,...
3
votes
1answer
45 views

htaccess conflicts

The issue that I'm currently forced to handle is related to a folder structure URL being redirected to the same folder structure URL but with a different string. So page-a used to exist but that ...
3
votes
1answer
37 views

What is the Cloudflare equivalent of these two .htaccess redirect rules?

I usually set up my sites to rewrite URLs in the following cases: All http traffic is redirected to https (and www), with a 301 All non-www traffic is redirected to www (and https), with a 301 In ....
1
vote
1answer
37 views

Use .htaccess to redirect to add .txt extension

I have a .txt file on my hosting and would like to redirect to it if somebody enters an specific website within their browser, e.g. example.com/webpage --> redirects to --> example.com/...
2
votes
1answer
25 views

I can't run 2 or more url rewriting rules at once

I was trying to shorten the URL more, but I was removing .php file extension from the URLs using URL rewriting too. I can't run both at the same time. Removing the extensions and trying to shorten ...
0
votes
0answers
32 views

Some links are indexable and some others are not when they are all created equal, why?

I'm trying to create a sitemap. I'm using the Screaming Frog software, but I think that this can be achieved in different ways with other software as well. My links are generated with different ...
1
vote
1answer
96 views

How can I change URL Letters from Upper to Lower case in htaccess for a specific folder?

I'm a bit stuck, so thank you for any help! In short I'm trying to convert either of the two examples (I have mod_rewrite from the first to the second already). I only want this to apply to the ...
2
votes
1answer
18 views

Apache redirection rules for wordpress sites

I want to redirect http://www.example.com/findyourname/ to http://www.newexample.com./findyourname/ http://www.example.com is a wordpress site , so when accessing http://www.example.com/findyourname/ ...
1
vote
1answer
61 views

Multiple pages under single directory redirection to a single Page

I have the following scenarios for web page redirects 1) All pages under www.oldexamplesite.com/page/product/New-Design/* and All pages under www.oldexamplesite.com/page/product/nature-of-design-...
1
vote
1answer
60 views

How to redirect all requests to HTTPS with SEO friendly URL using Apache?

First of all, I would like to leave remove www and redirect all request to HTTPS like this: RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} ^www\. [NC] RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$...
0
votes
1answer
38 views

Rewrite rule messes up direct links to directories

I have a very simple rewrite rule which does the job: allows link domain.com/index.php?page=NAME to be displayed as domain.com/NAME. The problem is when I try to give direct link to the image www....
1
vote
2answers
81 views

Issues with redirect rules to redirect all URLs except one page

I need to add following Apache redirect rules to .htaccess: http://www.example.com to be redirected to http://www.onemoreexample.com but http://www.example.com/support should not be redirected. To ...
1
vote
1answer
60 views

.htaccess rewrite stops working for javascript files after moving server

We recently moved an old PHP Project from a server using httpd to our regular prod. servers running apache2. In this project we have some reroute rules that map requests either to our index.php file ...
1
vote
1answer
116 views

Could someone explain what these .htaccess rules and “.well-known” conditions are for?

I am confused about both the purpose of .well-known exceptions and so many conditions. Is this just something temporarily put in place by the host or is it best practice to keep it in place? Why are ...
1
vote
1answer
41 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
39 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
31 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
71 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
64 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
180 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
50 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
213 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
39 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
45 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%{...
2
votes
1answer
98 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
84 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
37 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
152 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
133 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 ...
2
votes
1answer
170 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
85 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
1k 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
35 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
35 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
53 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
33 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
55 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
210 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
280 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
290 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
987 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
532 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
206 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.example.com/index.html?test=123$4/56 I should be ...