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

Questions tagged [htaccess]

Directory-level configuration file found mostly on Apache web servers

5
votes
1answer
3k views

What are the most commonly used and basic Apache htaccess redirects?

This question is here so we can offer users who are looking for information on how to make one or more common or basic redirects in Apache using the htaccess file. All future questions pertaining to ...
8
votes
1answer
5k views

.htaccess rewrite URL leads to missing CSS

I am trying to make my url from this: example.com/view.php?id=15 To this: example.com/watch/15 My code in .htaccess is as follows: Options -Indexes Options +FollowSymlinks RewriteEngine On ...
3
votes
2answers
931 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.
7
votes
3answers
38k views

How to remove trailing slashes from URL with .htaccess?

The situation Across the entire domain, we'd like the URLs to hide file extensions and remove trailing slashes, independent of the domain name itself (as in, works on any domain). Sample of our ...
10
votes
5answers
7k views

Forcing SSL and www in .htaccess

I'm looking for a way to force SSL and www. I've been able to force both separately but together I keep running into redirection issues. The following code works when handling a URL in this format: ...
2
votes
4answers
614 views

Redirect everything from old domain to new domain

I need to (permanent) redirect all of the following: www.example.com www.example.com/folder sub.example.com sub.example.com/folder Basically, all URLs that are reachable without being intended to: ...
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/. ...
5
votes
1answer
13k views

Help with 301 redirect from subdomain to root domain

I need to forward existing subdomain links to the root domain as the subdomain no longer exists. I have tried so many different lines of code in my .htaccess file and can not get the redirect to work. ...
14
votes
2answers
3k views

Is it better to have an ErrorDocument 404 redirect back to the homepage or a standard 404 error page?

We run an ecommerce site that was setup by a third party ecommerce software provider, basic shop with product pages, basket and checkout. The third party vendor set up the htaccess file so that if a ...
8
votes
3answers
16k views

htaccess redirect non-www to www with SSL/HTTPS

I want a rewrite rule that redirects everything to https:// AND www. For example http://example.com should be going to https://www.example.com This is what I have: RewriteEngine On RewriteCond %{...
3
votes
1answer
479 views

How can I block traffic from this referrer?

I'm getting a lot of spam referral traffic from semalt.semalt.com/referral on my website. I took a look at the link and there’s very little information about this. The number of website visits is ...
15
votes
4answers
640 views

Removing non-www support

I'm not an advocate of the no-www movement. I like the www because it adds as a buffer to distinguish between our public and private/static sites. The problem is that with one of our sites, our ...
12
votes
1answer
487 views

301 redirects for all except me

I want to have my site down for an hour and I was using order Deny,Allow Deny from all Allow from my.ip.add.ress but I don't like the default error page. Is there a 301 redirect where I can ...
6
votes
1answer
3k views

Redirect from SSL HTTPS to HTTP (NO SSL)

Many of my visitors have bookmarked my site already with https://mydomain.com. Under the bad advice of a programmer I have put my whole site (Joomla) using SSL. I do not sell anything or provide any ...
5
votes
1answer
3k views

redirect various http domains to certain https domain via htaccess

I have a bunch of domain names with different TLDs. What I want is to point several domains to the "main"-domain which has a SSL cert (single domain). Like this: https://maindomain.com (main domain ...
5
votes
2answers
1k views

Trigger IP ban based on request of given file?

I run a website where "x.php" was known to have vulnerabilities. The vulnerability has been fixed and I don't have "x.php" on my site anymore. As such with major public vulnerabilities, it seems ...
3
votes
1answer
177 views

.htaccess Redirect Old Threads

I have moved to mybb to vanilla and want to redirect old threads to the new format, so the indexed threads on Google aren't lost. The old format is showthread.php?tid=3003 Whereas the new format is ...
3
votes
1answer
550 views

Redirect www to non-www using Apache htaccess does not work

I have this in my .htaccess (modified from the default Drupal .htaccess): RewriteCond %{HTTP_HOST} ^www\.website.com\.com$ [NC] RewriteRule ^(.*)$ http://website.com/$1 [L,R=301] In theory this will ...
1
vote
1answer
214 views

Stop searches showing tld domain sites appearing as subdirectory of main holding site domain?

I'm not sure if this is a problem specific to how my hosting is structured or not. Let's say the main domain for my account is maindomain.com (for purpose of discussion). I am building other sites, ...
7
votes
1answer
427 views

home page of my site is not appear in google search, when I type site:example.com

I am totally confused, when I place site:example.com in google I see every page of my website in serp(search engine result page) except the home page. I don’t know why it’s happening but I check ...
6
votes
2answers
992 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 ...
4
votes
3answers
3k views

Subfolder won't permenantly redirect to subdomain

Right now I have the following code to redirect all non-www URLs to www URLs: RewriteCond %{HTTP_HOST} ^example.com RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] Besides that redirection, I ...
4
votes
1answer
1k views

redirecting openshift rhcloud domain to custom domain for SEO purposes

Openshift application url: example.rhcloud.com Custom domain: example.com I came across this link and added the redirection rule. However, I can not access example.rhcloud.com now. My custom domain ...
3
votes
2answers
186 views

Not able to stop hotlink

I am using following htaccess code to stop hot linking my image files Options +FollowSymlinks Options +SymlinksIfOwnerMatch RewriteEngine on RewriteCond %{HTTP_REFERER} !^http://(.+\.)?article-stack....
2
votes
2answers
707 views

How do I use a htaccess redirect to force www and use the .org domain while maintaining the URL path?

I have found this rule that does about 90% of what I want, but not quite everything. My main goals for the redirect are to 1) force www. 2) redirect .com to .org. This does that, but if I were at www....
2
votes
1answer
1k views

Multilingual and SEO URLs - best practice?

What would you recommend as a URL structure for setting up a multilingual site when optimizing for SEO? I'm thinking: www.yoursite.com/en/some-category/some-article/ www.yoursite.com/sv/en-kategori/...
1
vote
1answer
347 views

CDN virtual subdomain causes duplicated content

I have created a subdomain and a CNAME record which points to the domain root. The subdomain www.static.example.com is actually a copy of the entire website www.example.com and it is supposed to act ...
1
vote
4answers
2k views

Using a .htaccess to RewriteRule and Redirect 301 at the same time?

I have a couple of specific URLs that I want to display differently on my website, like this: RewriteRule ^contact$ contact.php To get ride of the ".php" extension. And to be SEO friendly (to avoid ...
1
vote
1answer
134 views

htaccess force ssl

I need to force all traffic for all pages on example.com to https://www.example.com . After much googles, and hosting site help docs, the consensus (and what my hosting - BlueHost - docs say to do) ...
1
vote
1answer
867 views

Redirect http www and non-SSL domains to HTTPS without multiple redirects?

I'm losing link juice in multiple redirects. I need to redirect all domain versions to my default domain i.e. https://example.com By all domain versions I mean http://www, http://, https://www and ...
1
vote
3answers
169 views

Can secret URLs be used to protect files?

I would like to know if I can offer private downloads in my website (only available to certain users) by placing all the files in a /download folder and make sure it doesn't show the index of all the ...
1
vote
2answers
3k views

.htaccess and browser caching

I ran across these suggested htaccess edits. Is this a good practice? Is this something I should implement on my wordpress site?: <IfModule mod_expires.c> ExpiresActive On ExpiresByType image/...
1
vote
1answer
112 views

I need a little help with .htaccess rewrite

I need a little help with .htaccess file I have songs, singers and albums links I want to rewrite. I all ready rewrote the links and they are like this: the links for the songs is like this: /song/...
17
votes
4answers
757 views

How do I implement URL rewriting in my .htaccess file?

I'd like to do some URL rewriting (Why? See this question.) so that instead of users seeing addresses like labouseur.com/course-compilers.html they can instead see and use simply labouseur.com/...
14
votes
1answer
73k views

Font blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin'

we are experiencing this error in Google Chrome. We thought everything was set-up correct. But maybe not? Font from origin http://skin.cdn.com has been blocked from loading by Cross-Origin ...
10
votes
10answers
23k views

Need to Stop Bots from Killing my Webserver

I am having EXTREME bot problems on the some of my websites within my hosting account. The bots utilize over 98% of my CPU resources and 99% of my bandwidth for my entire hosting account. These bots ...
6
votes
3answers
14k views

Properly force SSL with .htaccess, no double authentication

I am trying to force SSL with .htaccess on a shared host. This means there I only have access to .htaccess and not the main VirtualHost configuration. I know you can put a rule in the VirtualHost ...
7
votes
2answers
26k views

How to redirect any URL to lowercase URL?

I am using: <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteRule (.*) http://example.com/$1 [L,R=301] <...
7
votes
1answer
113 views

Restrict access to directories hosting different sites

My hosting provider requires that my primary domain (let's call it example.com) points to my public_html root. I also own several other domains (let's call them exampleA.com and exampleB.com) that are ...
8
votes
4answers
35k views

How to verify what modules are active on my server?

While trying to solve a problem on my website, a recommendation about my .htaccess file I got was First of all, please check on the server for all the different modules if they are enabled, and ...
2
votes
2answers
23k views

.htaccess language redirects with SEO-friendly URLs

How do I setup my .htaccess file to detect several languages, and redirect them to specific SEO-friendly URLs? Basically every URL needs to go to index.php?lang=(...). So, for English language ...
7
votes
4answers
14k views

How to Remove Extensions From, and Force the Trailing Slash at the End of URLs?

Example of current file structure: example.com/foo.php example.com/bar.html example.com/directory/ example.com/directory/foo.php example.com/directory/bar.html example.com/cgi-bin/directory/...
6
votes
2answers
600 views

Make .URL shortcuts into functional links within a Directory Listing

I use a lot of directory listing on my website and want to make .URL shortcut files into functional links. These .URL shortcuts were made by dragging the websites' icons from my Firefox URL bar to my ...
9
votes
1answer
6k views

Alternative to .htaccess (due to bad performance)

I've been told that .htaccess should be avoided when possible, as it reduces the server performance and new servers disable it or just don't implement it any more. I don't know how true this is, but ...
5
votes
2answers
1k views

How do I setup authentication on a specific folder using .htaccess?

I have a folder that I want to host files privately on my webserver. How do I go about making it password protected using .htaccess? Note: Nothing monolithic, I want something that is simple/easy so ...
5
votes
2answers
389 views

Properly redirect a site to WWW and HTTPS

I recently found out a problem in .htaccess file in my website. When I started the site I did a 301 redirect to redirect all non-www and http request to www with https. I added this lines of code and ...
4
votes
6answers
803 views

SEO - which URL's are the best?

I'm using .htaccess with RewriteRule to create SEO-friendly URL's. However, I have a few questions about this: First of all, I noticed many websites end their URL's with .html (or another extension)...
4
votes
1answer
365 views

.htaccess 301 redirect dynamic URL with regex?

How to do this with regular expression? Old -> New http://www.example.com/cat1/cat2/cat3/tool-model-10 -> http://www.example.com/tool/tool-model-10 http://www.example.com/cat1/cat2/cat4/tool-...
4
votes
1answer
5k views

How to redirect HTTPS to HTTP behind proxy (CloudFlare)

I want to redirect HTTPs to HTTP, I tried following code in .htaccess file Options +FollowSymlinks RewriteEngine on RewriteCond %{SERVER_PORT} ^443$ RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=...
4
votes
1answer
5k views

Clean URLs without PHP file extension

I want to make my URLs clean, for example: http://sample.com/about-me instead of: http://sample.com/about-me.php This is my code: RewriteEngine On RewriteBase / RewriteCond %{...