How do I turn off RewriteEngine redirect -- in htaccess file -- on localhost xampp on my local WIndows computer

Rowby Goren
Rowby Goren used Ask the Experts™
on
Hello Htaccss  Experts :)

I have an htaccess file that has, near the end, a rewrite section that redirects the site to another url.

I don't want that redirect to happen, but I'm not sure how to change that htaccess file.

It's running on xampp that I installed on my local windows based server, for testing locally on Localhost.

I have changed the redirect to google, for privacy issues.   But I just want there to be NO redirect. It's a WordPress site that I just want to run locally for some testing. WordPress has been successfully installed.

Below is a snippet from the end of the .htaccess file   My snippet starts a few lines before the rewrite engine section -- and goes all the way to the end of the .htaccess file

ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://www.google.com/$1 [R,L]
# Use PHP70 as default
AddHandler application/x-httpd-php70 .php
# BEGIN custom php.ini PHP70
<IfModule mod_suphp.c>
    suPHP_ConfigPath /home3/zzz/public_html
</IfModule>
# END custom php.ini

Open in new window


Would just changing "rewriteengine" to öff do it?

As I said, I am running this on my local computer using xampp   (which I haven't used for a while, but I got localhost working on it.)

Thanks!
Rowby
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David FavorFractional CTO
Distinguished Expert 2018

Commented:
Best not to disable rewrite engine as this will break all sorts of things inside many CMS systems + PHP frameworks (depending on settings).

Just comment out the lines you'd like disabled.

Author

Commented:
Thanks, David

Can you give some examples on my code example, where I would comment out the code around the area where the redirect is.

I’m not familiar with the specifics of the rewrite code and the best way to comment out on n htaccess.
btw this is a test site and not live to the public,  so I can test and restore the original code as needed

Rowby
Top Expert 2016

Commented:
RewriteEngine On 
# RewriteCond %{SERVER_PORT} 80 
# RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
# RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
# RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
# RewriteRule ^(.*)$ https://www.google.com/$1 [R,L]

Open in new window

Fractional CTO
Distinguished Expert 2018
Commented:
Take a look at David Johnson comment.

In general, you leave RewriteEngine On, to ensure random occurrences of rewrite rules scattered about continue to work, then comment out all other directives which begin with Rewrite*.

Caution: Doing this will break things you likely require, like commenting out acme-challenge will break LetsEncrypt SSL renewals.

Also the rule RewriteRule ^(.*)$ https://www.google.com/$1 [R,L] makes very little sense as this will redirect all incoming requests to Google.
_______

Side Note: You've made a potentially problematic mistake with your last RewriteRule. Here's the scenario I see on projects people ask me to fix.

1) Let's say your site is foo.com and....

2) You've had RewriteRule ^(.*)$ https://www.google.com/$1 [R,L] in place for months.

3) Setting [R,L] actually means [R=301,L] so a permanent redirect.

4) All major browsers cache 301s till the sun goes nova (forever).

5) This means anyone visiting foo.com while this rule is in effect will have a 301 redirect cached in their browser forever, so whenever they type in foo.com they will redirect to google.com forever, no exception, no fix. Period.

6) So if you're trying to recover from visitors being redirected to google.com you can't, because you have no access to their browser cache.

You'll have to way till they they clear all their cached content, before anyone will ever see foo.com again.

7) The fix for this is always make your flags something like [NC,L,R=302] as 302s are never browser cached, so if you make a mistake, like what seems to be a mistake above, then you can simply correct your mistake + people will instantly stop being redirected to google.com, then see foo.com instead.

This will happen instantly, because 302s by definition have an instant expiration time associated with them.

Author

Commented:
Thanks!

That David for that detailed explanation.

It also explained a mystery when I had completely removed a site and the domain was still being redirected.  

I had removed the htaccess and I was baffled why the site kept being redirected.  I had removed every single file and folder -- but the site was still redirecting to the second domain.

So your explanation really helped me!  Sometimes redirects can be "dangerous" --- especially if they are  "forever"

2) You've had RewriteRule ^(.*)$ https://www.google.com/$1 [R,L] in place for months.

3) Setting [R,L] actually means [R=301,L] so a permanent redirect.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial