I'm getting started using Bedrock and Lumberjack and I'm trying to simply get a "Hello World" example working. So far no success. I've added a couple of routes and created a controller but whenever I go to example.com/Test or /hello-world I get a 404 error.
Can anyone help me resolve this?
Within my Wordpress theme routes.php file I have:
<?php
use Rareloop\Lumberjack\Facades\Router;
use Zend\Diactoros\Response\HtmlResponse;
Router::get('Test', function () {});
Router::get('hello-world', function () {
return new HtmlResponse('<h1>Hello World!</h1>');
});
I also created a test controller:
<?php
namespace App\Http\Controllers;
use Rareloop\Lumberjack\Http\Controller as BaseController;
class TestController extends BaseController
{
public function __construct()
{
add_filter('wp_title', function ($title) {
return 'TEST TITLE';
});
}
public function show()
{
return 'Hello World';
}
}
I had the same issue and I resolved it by including an .htaccess in the root of my project folder with the following content:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Related
I am very new to CodeIgniter and .htaccess protocols so bare with me. None of the assets in my assets folder are loading. Including the favicon. I have 3 errors when I inspect the home.php page but all of the file paths appear to be correct.
I fear the issue could lie in my .htaccess file at the root of my project. This is my directory structure:
App/
Views/
pages/
home.php
public_html/
.htaccess
assets/
css/
light-theme.css
img/
shapes-background.jpg
index.php
favicon.ico
My controller App\Controllers\Home.php
class Home extends BaseController
{
public function index()
{
$data['title'] = 'Home';
echo view('templates/index_header', $data);
echo view('pages/home');
echo view('templates/footer');
}
public function view($page = 'home')
{
if (! is_file(APPPATH . 'Views/pages/' . $page . '.php')) {
throw new \CodeIgniter\Exceptions\PageNotFoundException($page);
}
$data['title'] = ucfirst($page);
echo view('templates/index_header', $data);
echo view('pages/' . $page, $data);
echo view('templates/footer', $data);
}
}
This is my .htaccess file:
# Disable directory browsing
Options All -Indexes
# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------
# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
# RewriteBase /
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Rewrite "www.example.com -> example.com"
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to the front controller, index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|img|js|css|content|uploads|profile|favicon.ico|light-theme.css|)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]
# Ensure Authorization header is passed along
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Allow phpmyadmin access
RewriteCond $1 !^(phpmyadmin|index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
# Disable server signature start
ServerSignature Off
# Disable server signature end
Here is how I reference my css file:
<!-- Stylesheet file -->
<link rel='stylesheet' type='text/css' href='<?= base_url('assets/css/light-theme.css?version=51'); ?>' charset='utf-8'>
And here is how I reference an image to display:
<img src="<?= base_url(); ?>img/shapes-background.jpg" alt='Various Shapes'>
My baseurl is set inside App/Config/App.php:
public $baseURL = 'http://localhost/Shape_Search/index.php/';
I am trying to create a multi language word press website. Here is my .htaccess file info
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en|hn|ta)/(.*)$ /$1 [L,P]
RewriteRule . /index.php [L]
The situation would be
http://website-url/en/home and http://website-url/hn/home and http://website-url/ta/home should point to http://website-url/home. I looked up for many articles and I couldn't find any solution.
Thanks.
let's try the below code maybe it will solve your problem
function lang_support() {
return array('en','fr'); // Add your support lang-code (1st place is a default)
}
function rewrite_lang(){
$langs = lang_support();
foreach($langs as $lang) {
add_rewrite_endpoint($lang,EP_PERMALINK|EP_PAGES|EP_ROOT|EP_CATEGORIES);
}
}
add_action('init','rewrite_lang');
function lang(){
global $wp_query;
$langs = lang_support();
$lang_r = "";
foreach($langs as $lang) {
if(isset($wp_query->query_vars[$lang])) {
$lang_r = $lang;
$_SESSION['lang'] = $lang_r;
}
}
if(in_array($lang_r,$langs)) {
return $lang_r;
} else {
return $langs[0];
}
}
function init_session(){session_start();}
add_action('init','init_session',1);
function lang_session() { // Redirect by JS if session is set
$url_lang= basename($_SERVER['REQUEST_URI']);
if(!in_array($url_lang,lang_support()) && isset($_SESSION['lang'])) {
if(!is_404()) {
wp_redirect(currentURL().$_SESSION['lang'],301);
exit;
}
}
}
add_action('wp_head','lang_session');
function output_buffer() {ob_start();}
add_action('init','output_buffer');
function currentURL() {
$pageURL=(#$_SERVER["HTTPS"]=="on")?"https://":"http://";
if($_SERVER["SERVER_PORT"]!="80"){
$pageURL.=$_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
}else{
$pageURL.=$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
Add this code in functions.php. After added code go to wp-admin/options-permalink.php and press Save Changes
So now you can check/use the lang code in your template like...
<?php echo lang();?>
or if( lang() === "en" )
Example work URLs with my example code :
http://example.org/ <-- "en"
http://example.org/en/ <-- "en"
http://example.org/fr/ <-- "fr"
http://example.org/es/ <-- "en" (coz , "es" code not set)
http://example.org/mypage/ <-- "en" (work with "page")
http://example.org/mypage/fr/ <-- "fr"
http://example.org/mypage/es/ <-- "en" (coz , "es" code not set)
http://example.org/mypost/ <-- "en" (work with "post")
http://example.org/mypost/fr/ <-- "fr"
http://example.org/mypost/es/ <-- "en" (coz , "es" code not set)
I am using a webservice for finding ip's country info.When I use below code , wordpress automatically redirect "http://api.wipmania.com/jsonp?callback=jsonpCallback" to " https://api.wipmania.com/jsonp?callback=jsonpCallback " and give this error."GET https://api.wipmania.com/jsonp?callback=jsonpCallback net::ERR_CERT_REVOKED"
why worpress adds -s to my link.
how to fix this error.
Note: It works on Mozilla but at Chrome it does not work.
thank you.
<script type="text/javascript">
function jsonpCallback(data) {
console.log (data);
}
</script>
<script src="http://api.wipmania.com/jsonp?callback=jsonpCallback"
type="text/javascript"></script>
htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
# END rlrssslReallySimpleSSL
# 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>
check for this meta in your website source
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
Practically this redirect all http request to https, some SSL plugin for wordpress add this automatically or by setting an option.
I used this code for a similar situation. I am not sure if it will help for yours though.
function fix_https_link($url, $path, $orig_scheme, $blog_id){
$ssl_enabled = false;
$options = get_blog_option($blog_id, "rlrsssl_options");
if ($options && isset($options)) {
$site_has_ssl = isset($options['site_has_ssl']) ? $options['site_has_ssl'] : FALSE;
$ssl_enabled = isset($options['ssl_enabled']) ? $options['ssl_enabled'] : $site_has_ssl;
}
if (!$ssl_enabled) {
$url = str_replace("https://","http://",$url);
}
return $url;
}
add_filter( 'home_url', 'fix_https_link' , 10,4);
I'm using Zend-Framework and below are the code of my htaccess.
rewriteEngine On
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ https://www.mysite.co/$1 [R=301,L]
RewriteCond %{http_host} ^mysite.co [NC]
RewriteRule ^(.*)$ https://www.mysite.co/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Now I want to force http on mysite.co/news/* and https on all other pages. So how can i apply rule?
You can define your controller and action and put this code into that condition, for that you can use bootstrap of zend framework.
like:
if($_SERVER['SERVER_PORT'] == '443') {
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit();
}
Or you can use this bootstrap method
protected function _initForceSSL() {
if($_SERVER['SERVER_PORT'] == '443') {
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit();
}
}
There exists the isSecure() function that lets you know if it is a https request (true) or http (false).
You can try to go through a plugin like this to redirect your query:
class Application_Plugin_SSL extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request){
if (!$request->isSecure()){ // -> not https
$request->setModuleName('yourmodule')
->setControllerName('yourcontrolle')
->setActionName('youraction')
->setDispatched(true) ;
}
}
}
I want to rewrite http://website.com/?slug=product_info.php&products_id=32 to http://website.com/product_info/32 and I use this code,
add_filter('rewrite_rules_array','wp_insertMyRewriteRules');
add_filter('query_vars','wp_insertMyRewriteQueryVars');
// Adding a new rule
function wp_insertMyRewriteRules($rules)
{
$newrules = array();
$newrules['(product_info)/(\d*)$'] = 'index.php?pagename=store&slug=product_info.php&products_id=$matches[1]';
return $newrules + $rules;
}
// Adding the bid var so that WP recognizes it
function wp_insertMyRewriteQueryVars($vars)
{
array_push($vars, 'products_id');
return $vars;
}
I also used this code,
add_action( 'init', 'wpse41778_add_rewrite' );
function wpse41778_add_rewrite()
{
add_rewrite_tag('%products_id%','([^/]+)');
add_rewrite_tag('%slug%','([^/]+)');
add_rewrite_rule(
'^product_info/([^/]+)/?$',
'index.php?pagename=store&slug=product_info.php&products_id=$matches[1]',
'top'
);
}
I have manually flushed the rules but when i go to http://website.com/product_info/32 it went to http://website.com instead of the product page. Both of the codes have this kind of issue.
Here is the contents of my .htaccess,
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
RewriteRule ^login$ /wp-login.php [L]
RewriteRule ^signup$ /wp-signup.php [L]
RewriteRule ^register$ /wp-register.php [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]
I don't know whats the problem and Im actually newbie on this. Please help.
Rules are not flushed, add this code to flush them automatically:
add_action('wp_loaded', 'my_flush_rules');
// flush_rules() if our rules are not yet included
function my_flush_rules(){
$rules = get_option('rewrite_rules');
if (!isset($rules['(product_info)/(\d*)$'])) {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
and make sure your .htaccess file is writable by Wordpress