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
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [htaccess]

Directory-level configuration file found mostly on Apache web servers

0
votes
0answers
3 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 ...
1
vote
1answer
14 views

Redirect to homepage based on server error code with htaccess

I just took over management of a small HTML website. I discovered the security on the website was almost non-existent because full directory browsing was possible. I have since disabled directory ...
7
votes
3answers
4k views

.htaccess permanent redirect to www

I have a WordPress installation that is not redirecting URLs not starting with www. Example: http://example.com/dir/ doesn't send to http://www.example.com/dir/ instead goes to http://example.com/. ...
2
votes
1answer
29 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
17 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 [...
1
vote
2answers
626 views

Forcing trailing slash at end of “fake” folders

The working codes that I've found here most put a slash in everything. I just need force trailing slash in these "fake dirs" (that are part of my rewriting scheme (only directories)) and keep ...
5
votes
2answers
369 views

Implement lots of redirects (a million) without slowing down the site

What's the best way to redirect 1,000,000 unique URLs to another 1,000,000 unique URLs? These pages are all combinations of multiple search filters and queries. We're migrating the site to cleaner ...
3
votes
1answer
52 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 ...
1
vote
1answer
27 views

How to redirect from blog.example.org to example.com using htaccess

I have tried all means to do a 301 redirect from blog.example.org to https://www.example.com/post using .htaccess but the redirect doesn't seem to be working. I'm using this code below; ...
2
votes
2answers
2k views

getting 500 intenal error when setting 301 redirect using .htaccess

I am trying to use a 301 redirect to direct users and bots to my new site but when I put the .htaccess live I keep getting a 500 internal error shown. The site is actually a subdomain which i want ...
3
votes
1answer
42 views

Redirect domain name to a specific page

I have theses domain names installed: Main domain name: www.example.com Others domains: www.example.org www.example.fr www.animals.example I first made a rule on my .htaccess to redirect all ...
1
vote
1answer
1k views

Content-Security-Policy doesnt work on my site?

I tried this CSP: Header set Content-Security-Policy: "default-src 'self'; script-src 'self' https://www.google-analytics.com; style-src 'self' https://twemoji.maxcdn.com; img-src 'self' https://...
0
votes
0answers
22 views

301 Redirection Help for Moving New Domain with New Directory

I have a WordPress website on example.com with 500+ pages. I need to move this site to newsite.com/blog/ I searched this on Google the whole day, but couldn't find how to write 301 for my ...
1
vote
1answer
44 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) { ...
1
vote
1answer
34 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/...
0
votes
1answer
37 views

301 Redirect not working as expected

I am in the process of doing a website redesign. We have changed the domain name and hosting server for the new project. Following are the rules that I am using in my htaccess file to perform a 301 ...
1
vote
2answers
50 views

I have a page with two domains and I want to redirect one of the domains to a specific page via htaccess

I am using the domains ergonomi.example and fysiarbejdsliv.example I want fysiarbejdsliv.example to redirect to https://fysiarbejdsliv.example/dansk-selskab-for-fysioterapi-i-arbejdsliv. I have ...
1
vote
1answer
22 views

Alias subdomain to subfolder (not redirect) with .htaccess (with HTTPS), error ERR_TOO_MANY_REDIRECTS

Well, I'm trying to accomplish this task by using this .htaccess: Options +FollowSymLinks RewriteEngine On # HTTPS (not working: ERR_TOO_MANY_REDIRECTS) # RewriteCond %{HTTPS} off # RewriteRule (.*)...
0
votes
0answers
19 views

Configure apache forwards my site to index.php for root [closed]

Struggling with following issue: CPanel on shared hosting force index to be index.php and fowards any requests to root i.e. '/' to it. I already tried to use htaccess file to override this - without ...
2
votes
1answer
33 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
1answer
24 views

redir everything in a folder, but not certain pages - htaccess

How can I edit my .htaccess file to redir everything in a folder, except 3 pages on that same folder Redir everything here: /site/ but exclude /site/page-1.html /site/page-2.html /site/page-3.html ...
0
votes
2answers
1k views

Where to place 301 redirects in the .htaccess file on a WordPress site

I edited my .htaccess file earlier to redirect from www version to non-www, and it is working correctly. However, now I have some page redirects I need to do. I am looking at the .htaccess file, and I ...
0
votes
1answer
43 views

Where to place 301 redirects in my Wordpress htaccess file?

I have about 25 301 redirects in my Wordpress htaccess file, that look like this: Redirect 301 /store/index.html https://www.notesinspanish.com/store-home/ At the moment they are at the bottom of my ...
1
vote
1answer
49 views

Redirecting 404 pages to another active pages in .htaccess

I have one product page indexed on Google but that link does not exist anymore and hits 404 page. What I want to do is to redirect that link in .htaccess to another product page since it ranks very ...
1
vote
1answer
45 views

How to redirect dynamically generated duplicate pages in .htaccess?

I have over 2000 dynamically generated duplicated pages like this: https://www.example.com/subfolder/page1.html and https://www.example.com/subfolder/page1/ What i am trying to do is redirect all /...
2
votes
1answer
21 views

How to form redirect or rewrite where query string contains portion I want to extract to new query string

I've transferred an old custom-made site to Mediawiki and I have many internal and external links to my old pages that I want to redirect to the appropriate wiki page. There are many links to the ...
1
vote
1answer
22 views

.htaccess: Redirect all HTTPS to a subdomain, but EXCLUDE one subdomain folder

In summary: (Notice the "https") I have https://www.example.com All need to be re-directed to https://sub.example.com EXCEPT https://xyz.example.com/api Here is my current .htaccess: ...
1
vote
0answers
39 views

After implementing HTTPS, “require valid-user” in subdirectory no longer asks for password, just gives 401 Not Authorized

I'm not very knowledgeable about server scripting, however I've only just installed SSL certificate for the domain. The main website (hosted by GoDaddy) is now working fine on SSL/TLS and I've ...
1
vote
1answer
51 views

Adding a subdirectory to a URL using .htaccess

I am trying to achieve the following: This URL: www.example.com/wis/9-3/1998/0.general Redirected to this URL: www.example.com/9440/wis/9-3/1998/0.general So I'm trying to add this subdirectory to ...
1
vote
2answers
86 views

Does hotlinking image protection hurt search engines indexing?

Several websites are hotlinking my images, I want to block and prevent hotlinking to my website images. And, I was going to use standard hotlink prevention code in .htaccess: RewriteEngine on ...
0
votes
1answer
31 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
20 views

Rewritting .htaccess file to direct to files using a wildcard

Currently my html code points to www.example.com/images/sub/ABCimage.jpg www.example.com/images/sub/XYZimage.jpg Due to a limit on number of files (9999) within the folder , I had to split images ...
1
vote
1answer
27 views

Redirecting all subdirectories of a folder via htaccess [duplicate]

I've searched around and haven't found this specific question asked. I need to redirect all the 'subfolders' of a directory to the parent directory. For example, the parent directory is example.tld/...
2
votes
2answers
73 views

How would Google react if I redirected currently ranking landing pages to the home page?

I have some tag pages on my website which contain specific keywords. They appear in the Google search results for those keywords. Those pages bring in a fair amount of traffic but the bounce rate is ...
2
votes
3answers
157 views

When I have multiple .htaccess files between several sites, which is the active one?

I have 4 sites hosted with the same ISP. The sites were modified endless times, and now, I have several .htaccess files. One of the is at the main root. The others are spread in different places. For ...
3
votes
1answer
23 views

500 error after migrating from Easy Apache 3 to EA4 on Centos6 VPS

I made the mistake of clicking the button in WHM to migrate from Easy Apache 3 to EA4 and now I am receiving a 500 error when I try to visit my site. What have I broken and how can I troubleshoot the ...
3
votes
1answer
78 views

When splitting a folder with tens of thousands of documents into several folders, how can I handle broken links?

I have over 30,000 html files stored in www.example.com/docs, and these files are linked to each other. When it comes to displaying the content of those files on my site, I use the following code: ...
2
votes
2answers
2k views

htaccess and 301 redirects - multiple domains

I have the following which redirects mydomain1.co.uk and mydomain1.com to www.mydomain1.com perfectly. RewriteCond %{HTTP_HOST} !^(.*)\.mydomain1\.com$ [NC] RewriteRule ^(.*)$ http://www.mydomain1....
1
vote
1answer
81 views

Redirect to remove everything after the second slash (first directory)

I'm trying to redirect a lot of pages on a website I own. There are a few pages indexed and I need to fix them for example: /vloerafwerking/projecttapijt/raamafwerking/ needs to go to /vloerafwerking/...
0
votes
0answers
33 views

.htaccess clean url to GET variable with WordPress

I'm struggling to get a .htaccess rule to work. I'm trying to cleanup a URL for a WordPress site. Instead of /illustration?rid=123, I'd like /illustration/123. I've tried solutions from many of the ...
1
vote
1answer
40 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
16 views

Don't allow access to example.com/image/pic.jpg using htaccess

I have two domains for the same website. example.com and example2.com . I don't want the /image/pic.jpg to be accessible for the example.com It means, if someone try to visit example.com/image/pic....
0
votes
0answers
12 views

How to enable .htaccess Gzip? [duplicate]

#Gzip <ifmodule mod_deflate.c> # compress text, html, javascript, css, xml: AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/...
0
votes
0answers
20 views

Redirect IP address to domain using .htaccess [duplicate]

I tried the following .htaccess code to redirect the IP address of my VPS server to my domain, but despite of all efforts it keeps resulting in a 404 error: RewriteEngine on RewriteCond %{HTTP_HOST} ^...
1
vote
1answer
52 views

htaccess rule doesn't work - NET::ERR_CERT_COMMON_NAME_INVALID

This URL: https://mqgmodas.com/rebajas/ Into the .htaccess I have: Redirect 301 https://mqgmodas.com/rebajas/ https://masqguapas.com/rebajas/ Also I have a redirection in my control panel saying ...
3
votes
2answers
20k views

Wild card redirection for HTTPS and Non-www version

I want to enable SSL for my main website and sub-domain websites. For SEO reasons, I need to redirect HTTP requests to HTTPS requests. I think I should do that using a wild card redirect in my ....
0
votes
0answers
26 views

Edit htaccess file to remove the slash at the end without disturbing https settings [duplicate]

My website URL has a slash at its end and appears like this https://mywebsite.com/ Since search engine reads https://mywebsite.com/ and https://mywebsite.com as two different URLs, I want to ...
5
votes
2answers
2k views

How can I serve all resources under HTTPS instead of HTTP without changing their URLs in the HTML code

I know that by using an .htaccess file I can redirect everyone to https://. However, my SSL certificate complains if all the content isn't served under HTTPS. Is there a way to convert all the ...
3
votes
0answers
33 views

Why are my HTML resources re-downloading despite having an expiration date a month in the future?

I have set the expiration information for my resources in the .htaccess file as shown below: <IfModule mod_expires.c> ExpiresActive on ExpiresByType image/jpeg "access plus 1 month" ...
2
votes
1answer
124 views

Return 410 gone status code for URLs containing same characters in .htaccess

My website was hit by the pharma spam attack which created hundreds of URLs, all of which contain the last 5 characters -1234.pdf. So that Google and other search engines will remove these quicker, ...