I am developing site on Codeigniter and want to "connect" it with Wordpress.
So the URL structure will be
SITE-URL
-SITE-URL/folder1/
--SITE-URL/folder1/some-link
-URL/folder2/
...etc
What I need to do, is when Codeigniter throws 404 error, the content is taken from Wordpress website(same relative URL) without any redirects for end user.
Thanks
Not sure you can do this with .htaccess since .htaccess can only do re-directions before the content is served, meaning before Codeigniter has responded to the request. So when Codeigniter generates a 404, it's returning content an .htaccess isn't processed.
What you would need to do is generate a 404 controller that either does a redirect, which you don't want, but would be the easiest. Or the 404 controller would then have to load in wordpress and process the request through there. Something similar to proxy, but it will need to be done with PHP.
Related
I am trying to understand how the URL resolution happens in WordPress. When a page is created/edited the internal link is something like the following:
example.com/wp-admin/post.php?post=165&action=edit
But to view the page, the URL used is something like the following:
example.com/about-us
How does WP resolve the public URL and generate the page?
As far as I can tell WordPress does this resolution using the .htaccess file. The rules are set in .htaccess to route the request to an index.php file which does the rest of the processing to generate the page.
This is specific to Apache. Other web servers may do it differently.
I have a site running on WordPress, and it will automatically redirects URLs it thinks are written incorrectly.
For example, if I go to a URL that doesn't exist. Like this one:
www.example.com/blah-blah/my-page-slug/
will redirect me to...
www.example.com/my-page-slug/
How can I stop this redirection? I want to generate a 404 error if the wrong URL is typed in, not redirect.
Place this in your theme's functions.php file.
remove_action('template_redirect', 'redirect_canonical');
On a wordpress site.
I'm updating the permalinks so that the posts go to /blog/title-of-post instead of right off the route. Problem then becomes all 400+ posts that are on the site will 404.
Rather that add a 301 redirect in the htaccess file for each of these, is there a better way?
Can I set the htaccess to detect the url, and if it 404s, to instead send the traffic to url.com/blog/the-rest-of-the-title, so that it passes the same url string but with /blog/ in front of it?
Hope this is clear, please let me know if there's any questions.
Thanks in advance/
this is possible only on apache 2.4+ . On apache 2.4 you can pass the 404 URI string to the destination url of ErrorDocument.
ErrorDocument 404 http://example.com/blog%{REQUEST_URI}
This example will not work on lower versions of apache as they dont understand the %{SERVER_VARIABLE}
I moved domain from http to https. And currently all http urls are redirected to https.
But there are some broken links from old urls such as http://domain.tld/url-link-broken and I would like to redirect them to the root domain.
The problem is that currently http://domain.tld/url-link-broken redirects to https://domain.tld/url-link-broken
How can I change this via htaccess so that if url is broken it would not only redirect to https but also to the root?
Check following things first
Your console gives any error there regarding resources
Check do you have static links in menu or anywhere else
Check your home_url and site_url in admin
Solution
Using Plugin:
Please Take Backup of database before proceed
https://wordpress.org/plugins/ssl-insecure-content-fixer/
For More Information :
https://managewp.com/wordpress-ssl-settings-and-how-to-resolve-mixed-content-warnings
I have built a few themes and noticed that the 404 pages, once uploaded to my server. never appear. They always do on my localhost setup, and even themes for others have worked.
I see no reason for it not to work, I have mod_rewrite enabled for the pretty permalinks but the 404 redirection seems not to want to work.
Is this a known issue?
Is it my shitty server with Streamline.net?
Can anyone help?
You can try setting your own error documents in .htaccess and that may override your hosts settings and that point to a static wordpress page called "error" or your 404.php in your theme
ErrorDocument 401 http://mydomain.com/error/
ErrorDocument 403 http://mydomain.com/error/
ErrorDocument 404 http://mydomain.com/error/
ErrorDocument 500 http://mydomain.com/error/
Edit: You can also do a redirect in your theme's 404.php file (yes, it's ugly...) to your static error page: <?php
Header("Location: http://mydomain.com/error/");
?>
If that doesnt work, I don't know.
Suffering from the same issue with Streamline. I guess it's due to the apache version used by this hosting 1.3.
If you have already a 404.php file in you theme template, if not create one. Then follow the steps below.
Step One: open you existing 404.php file in any editor, or create new one in theme directory.
Step Two: Copy/Paste below provided code in you 404.php file (make sure your 404.php file blank)
//404 Redirect to home in WordPress.
//Sara Domini
//301 Permanently Redirect
//http://2experts.net
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));
exit();
For me and other works like a charm :))
It's rather bizarre that this is happening. If WordPress is working with pretty permalinks, then Apache is doing it's job - rewriting any URL that doesn't physically exist to WordPress.
It's then up to WP to decide if the request doesn't match anything, and if so, display a 404.
Perhaps Streamline is screwing this up, by reading the '404 Not Found' header that WP kicks out and fiddling with the output?