RewriteRule exception for static page outside WordPress - wordpress

I'm searching Google since at least 20 minutes and I can't believe it's that hard to find...
It should be pretty easy but I can't figure it out...
THE PROBLEM:
I want to put a HTML file at the same level of my Wordpress, but don't want the RewriteRules to "trap" this page and think it's a redirect...
THE HTACCESS:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# >> here << this next line is my TEST....
RewriteRule ^test\.htm$ test.htm [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Of course, a page called "test.htm" is uploaded on the server.
As stated, the line where I put my test doesn't work. It shows the WordPress homepage, instead of my "test.htm" page I uploaded.

You might try this one:
RewriteRule ^test\.htm$ - [PT,L]
It passes through (PT) the request and does not apply any further rules (L).

Related

.htaccess file Wordpress RewriteRule Block Rearrange to the top

I was having issues (401 error) trying to reach my website via rest API. I moved the Wordpress block in my .htaccess file to the top and now my website is reachable. This is the first block that I now have in my .htaccess file?
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Do I need to combine the two lines of the RewriteRule lines like this? Does it change anything functionally?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Prior to me making any changes, the first block in the .htaccess file was:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
So by moving the "Wordpress block" it just adds the one line RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Do I need to combine the two lines
You certainly don't "need" to combine those two lines.
It will probably make no difference to accessing your rest API if you do.
A single, combined directive
By combining those two directives, as you have done, will mean the HTTP_AUTHORIZATION env var (used to help with HTTP Authentication) will only be set on requests that are routed through WordPress (including the homepage). And (on Apache*1) the REDIRECT_HTTP_AUTHORIZATION env var will not be generated when requests are rewritten to the WordPress front-controller (index.php), ie. page requests other than the homepage. Although I'm pretty sure that WordPress does not take advantage of this anyway. The HTTP_AUTHORIZATION env var will not be set on requests to static resources (images, CSS, JS, etc.) as it would have been before.
Two separate directives
With the two separate directives, as in the orginal code, the HTTP_AUTHORIZATION env var is set on every request, including requests for static resources. (But ordinarily, this is redundant.) And (on Apache*1) the REDIRECT_HTTP_AUTHORIZATION env var will be generated when requests are rewritten to the WordPress front-controller (index.php), ie. page requests other than the homepage.
(*1 As opposed to LiteSpeed, where env vars of the form REDIRECT_... are not generated anyway.)
I moved the Wordpress block in my .htaccess file to the top and now my website is reachable.
That isn't necessarily the correct thing to do. Ordinarily, the WordPress code block (the front-controller) should appear later in the file. There may have just been a single conflicting rule that should have been "modified" or perhaps moved to after the WordPress code block. But moving those directives to after the WordPress code block may effectively "disable" those rules entirely.
UPDATE:
Prior to me moving the "Wordpress" block to the top, this is what the
first block had:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
That code block is just an erroneous "copy" of the WordPress code block (less the HTTP_AUTHORIZATION var) and should be deleted altogether!

How to establish a main page by means of htaccess in wordpress?

I would like to establish a page of the site as the main one through htaccess, since in wordpress, within settings - reading does not appear.
I would like it to be redirected to domain.com/Business and if possible that / Business is hidden or not shown. If there is a plugin that does this, I would appreciate it. This is my .htaccess file
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Why not do it in your wp-config.php
Just put this:
define('WP_HOME','https://yourdomain.com');
define('WP_SITEURL','https://yourdomain.com');
Place it right after the opening <?php

.htaccess giving rewrite resulting in 404

am trying to get this simple RewriteRule to work:
RewriteEngine On
RewriteBase /
RewriteRule ^agb$ download/AGB.pdf$ [L]
RewriteRule ^impr$ impressum$ [L]
The file exists, and I can open it, if I manually open the url.
Now I have two problems with this.
The agb rule leads to a 404
The impr rule works (funny, as it has the same syntax as the agb rule), but it doesn't mask the url, it just changes it in the browser. Shouldn't the entered url stay the same, masked, not for the user to see, that there is some other URL behind it?
Many thanks.
*edit:
After following the advice to remove the $, I started playing around with the impr rule. Seems that the rule is not making the redirects, but wordpress is. Very try from /i over /imp to /impressu leads to the /impressum site. My bad, I didn't see this.
*edit:
The full file, as requested, looks like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^agb$ download/AGB.pdf$ [L]
RewriteRule ^impr$ impressum$ [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Okay - when reading the comment arkascha postet AGAIN AND COMPLETELY, it really were those $ on the target path.
Thanks a lot!!!!

Wordpress - pages stopped working - permalink issues?

I developed a simple wordpress site for a company.
Today they called me and said that some of the pages can't be visited.
So i checked it out , and seems like 3 menu options for apparent reason just stopped working. They said they haven't done any changes.
http://oi40.tinypic.com/ofqcev.jpg
Check the permalink it says says "projektledning" like it should be , and wordpress refuses to find the page.
http://oi40.tinypic.com/16h9mcg.jpg
And i tried for no reason to change the permalink and i've added "-1" to the link and bam its working...
What should i do to make the permalink work as the regular name it should be?
Try toggle permalink once under admin - settings - permalinks. Make sure you're server has write access to your .htaccess file before doing this.
.htaccess should look this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
At the last row, make sure there's a space between . and /
Also check your permalinks for any typos (spaces).
IF your url is foo.bar/something, make your .htaccess look like:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /something/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /something/index.php [L]
</IfModule>
# END WordPress
Hope this helps!

Rewrite rule in addition to Wordpress'

So, I'm trying to add my own RewriteRule in addition to what Wordpress already has. A little backgroun. The site I am working on is built off of a custom CMS, but also has a blog that is powered by WordPress. So, heres what I have thus far:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Custom rewrite for locatons
RewriteRule ^locations/(.*)$ /locations2.php?info=$1
# Wordpress rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
I also got rid of a couple lines of the Wordpress Rewrite code that seemed unecessary (everything still works....I think). But yeah, it seems like it is overwriting the rule that I wrote. Help?
Oh, also, I just tried to get rid of the . that is before /blog/index.php [L] and replaced it with just a ^, it worked...kind of. It loaded the blog when I went to /blog/, but when I went to something like /blog/author/admin, I got a 404.
I think you need to add the last flag [L] after your new rule, otherwise processing will continue and your request will be rewritten to '/blog/index.php'.
RewriteRule ^locations/(.*)$ /locations2.php?info=$1 [L]
Have you tried to remove the RewriteBase / and the slash before locations2.php ?
Something like this:
<IfModule mod_rewrite.c>
RewriteEngine On
# Custom rewrite for locatons
RewriteRule ^locations/(.*)$ locations2.php?info=$1
# Wordpress rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
If the blog gets unreacheable, move RewriteBase / to after the custom rewrite. Also, I believe that if the blog is in a sub-directory, the RewriteBase should be RewriteBase /blog/

Resources