Mobile app version of vmapp.org
Login or Join
Steve110

: Question about mod_rewrite rule for redirecting failing pages I'm setting up a mod_rewrite rule that redirects failing pages to a custom "Page Not Found" page. This is with WordPress. I've used

@Steve110

Posted in: #Apache #Htaccess #ModRewrite #Redirects #Wordpress

I'm setting up a mod_rewrite rule that redirects failing pages to a custom "Page Not Found" page. This is with WordPress. I've used an online tutorial from the Apache site and so far my rules look like this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+) example.com/?page_id=254 [R]


This works. It seems to be a combination of the first and second suggestion that worked, since the -U flag did nothing.

My question is, out of curiosity why the following happens: When I change REQUEST_FILENAME to REQUEST_URI (as the second example suggests), the page loads, but none of the style sheets load. All of my formatting is gone, and this happens on every page. Can anyone think of why this might happen?

10.04% popularity Vote Up Vote Down


Login to follow query

More posts by @Steve110

2 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

RewriteCond %{REQUEST_FILENAME} !-f



My question is, out of curiosity why the following happens: When I change REQUEST_FILENAME to REQUEST_URI (as the second example suggests), the page loads, but none of the style sheets load. All of my formatting is gone, and this happens on every page.


REQUEST_FILENAME and REQUEST_URI contain different values in per-directory htaccess files. REQUEST_FILENAME is the full local filesystem path to the file, whereas REQUEST_URI is the path component of the requested URI (which is not necessarily an actual file on the filesystem).

-f tests whether the TestString is a regular file, which the REQUEST_URI is often not - this is probably why requests for your stylesheets are being redirected.

It would seem, however, that the REQUEST_URI for your main page is being seen as a regular file (or other directives are getting to the request first). This will depend on your URL structure and possibly other directives in your .htaccess file.

10% popularity Vote Up Vote Down


 

@Angela700

For setting custom 404s, you should be able to do that much easier (even in .htaccess), like so:

ErrorDocument 404 example.com/?page_id=254

See also: ErrorDocument

Less messy and significantly less CPU use per request than mod_rewrite - anything that 404s just goes straight there, no questions asked. I'd definitely consider making any errordoc a static page if possible though, especially if you stretch it to handle other errors (no fun when your 500 errordoc throws a 500 error).

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme