Questions tagged [htaccess]

Directory-level configuration file found mostly on Apache web servers

Filter by
Sorted by
Tagged with
2
votes
2answers
3k views

.htaccess rewrite wildcard folder paths from host

My desired result is change a file to root / from a N number of paths. For example: www.host.com/a/b/c/e/f/g/images/1.jpg, where A~G is not always given. Result: www.host.com/images/1.jpg. This is ...
3
votes
1answer
31 views

Is there a way to set up a redirect in htaccess to convert a folder/paths to a params

After trawling through posts I have this RewriteCond %{HTTP_HOST} ^example.software$ RewriteRule ^downloads$ https://example.software\?mode\=downloads&%{QUERY_STRING} [R=302,L] This works fine ...
1
vote
0answers
28 views

Allowing POST requests to bypass Basic Auth if on given pages

Current Implementation: SetEnvIfNoCase Host ^example\.com$ passreq AuthType Basic AuthName "Restricted Area" AuthUserFile /html/.htpasswd Order Deny,Allow Deny from all Satisfy any Require ...
2
votes
0answers
30 views

Issue using htaccess to redirect to main domain's subdir for everything except specific subdomains (and subdirs)

Currently we have an htaccess setup using the below settings; RewriteCond %{HTTP_HOST} !^(staged|foobar)\.example\.com$ [NC] RewriteCond %{REQUEST_URI} !/(Press_Kits|logos|admin|console|shop)/ [NC] ...
2
votes
0answers
29 views

Anything here that can be blocking my site from being indexed by Google / Bing? [closed]

I'm unable to get my site indexed by Google or Bing. Robots and sitemap have been submitted but no love... I think the issue may be in the .htaccess file. Is there anything in here that may be causing ...
5
votes
2answers
646 views

HSTS implementation in .htaccess when using www subdomain

Been looking at implementing HSTS in to one of our sites, hoping to validate it on the preload list. But I can't get my head around how it works with the www. Subdomain. Our site forces secure www....
1
vote
0answers
56 views

301 redirect a subdomain and all its variants (https, www, etc) [closed]

I want to redirect 301 from abc.example.com to example.com/abc.html page. I would like to include all variants of the subdomain in the redirect, like abc.example.com www.abc.example.com https://www....
3
votes
2answers
382 views

How to Leverage Browser Caching for Fonts in WordPress

I am using WordPress along with Autoptimize and Cloudflare, and using Locally hosted fonts. I can't leverage browser caching on my site. I tried using Cloudflare Page rules to Leverage 1 year browser ...
2
votes
2answers
988 views

How to redirect a single web page other than using htaccess

I'd like to redirect a single web page, it will be a temporary redirect so I don't want it to affect SEO rankings. So I was thinking of using a method other than htaccess, but if it would be more ...
5
votes
1answer
761 views

Redirect percent encoded URL in .htaccess

Suppose I have the following URL: http://example.com/%D8%B3%DB%8C%D8%B3%D8%AA%D9%85-rss-%D8%B3%D8%A7%DB%8C%D8%AA-%D8%A8%D9%87%DB%8C%D9%86%D9%87-%D8%B4%D8%AF/ How can I redirect this to http://www....
9
votes
2answers
2k views

HSTS Preload section on .htaccess

Recently having moved a site to SSL, I looked into enforcing HSTS for eventual preload. The syntax is approved and the Chrome List allows it to be OK. However, not being a coder at all, a slight ...
5
votes
3answers
2k views

301 Redirects what does ([a-z]+)-(.*) and ([0-9]+)-(.*) mean

I just checked an .htaccess file with some custom redirects. There are two redirects I don't fully understand: RedirectMatch 301 ^/news/([0-9]+)-(.*) /blog RedirectMatch 301 ^/news/([a-z]+)-(.*)/$ /...
1
vote
3answers
4k views

Use .htaccess to redirect a number then extension differently than a number underscore letter followed by extension

How to do this with regular expression? Old -> New http://www.example.com/1.html -> http://www.example.com/dir/1.html http://www.example.com/2.html -> http://www.example.com/dir/2.html ...
3
votes
3answers
12k views

301 redirection removes UTM tags from URLs

A page redirects to another page using a 301 redirect in a .htaccess file. If I try to access the page from a URL with UTM tagging, after redirection, it removes all UTM tagging. Is this normal ...
2
votes
1answer
32 views

Use RedirectMatch in htaccess for many URLs

I need to redirect: https://example.com/thispath/beach?start=20 https://example.com/thispath/beach?start=40 https://example.com/thispath/beach?start=60 etc... to: https://example.com/thispath/beach ...
2
votes
1answer
50 views

Hide site from google search if visitors country is not Ukraine

I want to hide site from another countries but not Ukraine. It has to be hidden in google search. I heard that it could be done with Cloudflare but I don't know how to do this.
1
vote
1answer
2k views

Redirect all paginated pages to their main category page

I want to redirect all the paginated pages of the category pages to their respective category pages, because I don't want google to crawl the paginated pages. If my paginated category page URL is: ...
3
votes
1answer
176 views

How to redirect a URL and remove parameters using .htaccess?

I'm trying to redirect a URL ending with parameters to another URL without those parameters. https://example.com/newsroom/news-events/news.html?L=1&tx_news_pi1%5Bnews%5D=29&tx_news_pi1%...
2
votes
1answer
26 views

htaccess - RewriteCond is met, but RewriteRule doesn't run

I am trying to match both a filename and querystring in my .htaccess file. When using an online testing tool (this one), it tells me that the conditions are being met, but the following rule doesn't ...
1
vote
0answers
150 views

Use .htaccess to redirect to add .txt extension [closed]

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
54 views

Content that should be protected is served without authentication intermittently

Our website hosting is with a shared hosting provider. The only configuration we can make is through .htaccess files, we can't touch the apache configuration files that are sourced when apache first ...
2
votes
1answer
50 views

Block access to multiple files with .htaccess - RewriteRule and FilesMatch fail

I am trying to block access to specific files. Neither the RewriteRule or FilesMatch rules I have tried work on the live server, it serves the files as normal with status 200 OK (I'm expecting 404 ...
3
votes
1answer
75 views

sitemap.xml and serviceworker.js are location-sensitive files. But sensitive to the location in the request path or to the actual filesystem location?

I really like the idea of using .htaccess rewrite rules in combination with the /.well-known/ folder for keeping my webspace tidy and coherently / consistently organised. For instance, I know that ...
0
votes
1answer
2k views

301 redirect conflicts with cname redirect for both naked and www URL

Client had created a cname redirect for their www url which goes to their new web address, they were told to create a 301 redirect for the naked url but it's conflicting with the cname and the www url ...
1
vote
1answer
43 views

multilingual hreflang & .htaccess

I have found several questions concerning multilingual websites and .htaccess rewrite rules. Unfortunately I am only dealing with my website once a year and I am unable to interpret those answers to ...
1
vote
2answers
22k views

How to match only part of URL and redirect URL with parameters in .htaccess?

I have a number of links with similar structure: example.com/index.php/path/some-path/some-subpath?parameter=1 Which I want to redirect just to example.com/category/ But I want to match only the ...
1
vote
1answer
30 views

Wordpress multisite non-www URL redirects to mainsite. www version of url is okay and comes to subsite homepage. Why?

So I just made a subsite today and everything was okay until I noticed: If I type the URL of the subsite without the www part, it redirects to the main site. Does anyone know why is that? Before I ...
1
vote
1answer
94 views

A modern global rewrite command for HTTPS websites without cname (www.) at all

I host a MediaWiki website on a shared server with Apache, MySQL and PHP. Up until today I used a CDN to deliver that website's content --- which required redirecting each webpage to a www. including ...
1
vote
1answer
35 views

Https- and www-redirects accepted by Google Pagespeed Insights

This question builds on this stackexchange-thread The question of mentioned thread was how to write a proper http-to-https and nonwww-to-www redirect, that Google Pagespeed Insights would approve of. ...
1
vote
1answer
35 views

How can I redirect a new bare domain to its subdomain without hurting SEO? [closed]

I want to install my new site content on a subdomain like subdir.example.com instead of the root domain. This is a new domain and it has no previous content to redirect. The root URL will be empty and ...
7
votes
3answers
1k views

How to submit shortened URLs to Google so that they are included in the index

I am working on a project to create a URL shortener. I have successfully gotten it to create short URLs, but I would like to submit them to Google. When I submit a short URL via Google Webmaster ...
1
vote
1answer
439 views

How to replace '?' and `=` with slashes in a URL using .htaccess?

How to replace ? and = with / in the URL? I think it may be in .htaccess. Example: example.com/public/Micheal-Smith would look like example.com?public=Micheal-Smith if I didn't replace the ? and = ...
2
votes
1answer
36 views

301 Redirect from URL with query string to new URL without query string

I'm having trouble working out how to do a 301 redirect from: https://www.example.com/catalogue/catalogue.php?catSection=1 to https://www.example.com/hire-category/access-support-equipment/ I've tried ...
2
votes
1answer
425 views

Redirect query string URL via .htaccess

I am trying to redirect all query strings to a new URL. Search query example www.example.com/?s=cars to resolve to www.example.com/?search_gcse/?q=cars ("cars" is just an example). What is the ...
1
vote
1answer
22 views

Htaccess redirect rule adds an unwanted variable

I'm trying to redirect logged-in users that land on a page to another page, but the redirect keeps adding the logged-in user's name to the path / URL. Say I'm logged in as Mario. The redirect ...
2
votes
3answers
570 views

RewriteRule not working on new host for URLs containing a directory powered by a PHP file with the same base name

I just moved from a dedicated server to a shared server to save money, but now my htaccess file doesn't work. I think its 1and1, but I'm not 100% sure. What the heck is wrong? Any ideas? The single ...
0
votes
0answers
51 views

.htaccess script working in Chrome/Safari but not in Firefox

Purpose of the script is to allow traffic only if referred to from a link / php script on the website itself. Direct access to link should not be allowed. Referral from 3rd party website should also ...
1
vote
1answer
35 views

Safe way to block unwanted bots without potential impact on good ones

Currently, I have blocked several bots in htaccess (apache 2.4) like this. (Have used imaginary bot names in the below example.) SetEnvIfNoCase User-Agent .*abcbot.* bad_bot SetEnvIfNoCase User-Agent ....
1
vote
1answer
42 views

Can I use the .htaccess file or another solution to address www and non-www duplicate content issues?

Ahrefs is returning a series of duplicate content URLs for my own website i've asked them about and which they've said needs to be addressed on the CMS side, and which they cannot help with. The ...
1
vote
1answer
26 views

htaccess: request file by partial name

With the assistance of htaccess, is it possible to have files stored as... /content/001 Some sort of description.html /content/002 Some sort of description.html ...or as... /content/Some sort of ...
2
votes
0answers
32 views

Is “cbsearch.site” a web robot, and if yes, how do I block it?

I saw invalid traffic in my Google AdSense account. I read some articles from the web, which all made it clear that invalid traffic could be caused by web "robots". So I tried to read on how ...
1
vote
1answer
60 views

.htaccess directives fail to redirect www to non-www URLs

I'm trying to redirect https://www.example.com to https://example.com. I'm running Ubuntu server 2020 lts with Apache 2, PHP 7 and Let's Encrypt SSL. My file structure: logs/ private/ public/ └ ...
1
vote
1answer
103 views

Remove PHP extension from URLs such that the URLs work with or without a trailing slash

My directory structure is - Assets - Dashboard - index.php - account.php index.php about.php verify.php What I basically want it to be: Remove the .php extension for example http://example.org/...
3
votes
1answer
81 views

Force HTTP to HTTPS except one page accessed via HTTP

I'm trying to redirect a website to HTTPS, but there is one URL that needs to be accessed via HTTP. Currently I just have this in .htaccess: Redirect 301 / https://www.example.com I need to have the ...
0
votes
1answer
64 views

How to redirect an https site from www to non www

After adding an SSL certificate I want to 301-redirect all my site's URL variations to non-www ones. I tried creating a redirect from cPanel for all other variations. Every other URL variations ...
3
votes
1answer
59 views

IIS rewrite rules for SEO friendly URLs don't work in .htaccess for Apache

I'm using a Pi 3 for the Apache server but I can't figure out how to setup .htaccess. Previously I used IIS with which it is easy to implement SEO-friendly URLs. Linux .htaccess is very different and ...
3
votes
2answers
1k views

Website is under maintenance - how to restrict access?

Currently, my website is under maintenance. I want to be the only person who's able to access/view the website online until I finish maintenance. How to set restrictions to others? I hate stalkers.
4
votes
1answer
7k views

What do I put in htaccess to create a 410 error page when a URL parameter is present?

I tried to create a 410 error page but realized that I actually created a 302 redirect to a 410.php page. Instead I want to use a 410 error to block out an infinite number of dynamically created pages ...
3
votes
1answer
80 views

Combine multiple 301 redirects

I need to combine multiple redirects via my .htaccess in Wordpress for future site migration and re-launch: Domain change Force HTTPS Force www URL structure changes (important to keep juice here) I'...
2
votes
2answers
2k views

How can I log a user's actual IP address instead of CloudFlare's?

My raw access log is now filled with CloudFlare IP addresses. Is there any way I can use a .htacess file or configure the server to log the user's actual IP address? With PHP, CloudFlare creates these ...

1
2 3 4 5
32