I have installed WordPress in example.com. I have also installed CodeIgniter in ci folder here example.com/ci/, ci is the folder name , register is the controller name and working URL of CI is example.com/ci/register . My base URL starts with https:// .
Now I have one WordPress URL example.com/hotel, hotel is the page that I have created in WordPress admin, it works fine.
I want to run my CI path like example.com/hotel/ci/register, I think we can do it with some rewrite rule so that my URL would look like example.com/hotel/ci/register. I have added given htaccess for wordpress that redirecting me here example.com/hotel/ci/register. It is showing me 404 error of CI. It means now I am in CI. Now I did following things in routes.php file.
$route['default_controller'] = 'register';
$route['404_override'] = 'register';
Now this URL example.com/hotel/ci/register is working, but this is not right way, next time there will be more controllers then it will not work.
Note: I can not create hotel folder because hotel is a page in the WordPress. If I create hotel folder then WordPress URL example.com/hotel/ will not work. It will redirect WordPress page to the hotel folder. So I have to do it without creating hotel folder. Note example.com=myurl.com .
I need to find another good solution.Any advise or guidance would be greatly appreciated?
Following is my reWrite rule in wordpress htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/?hotel/ci/register(/.*)?$ /ci/$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
And following is my CI htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
Interesting problem! I set up a Docker container with a fresh install of Wordpress and Codeigniter, I created a hotel page in WP, and a Register controller and view in CI, and got testing. I spent way too long on this, but I did find an answer.
First, your Wordpress .htaccess. As #tobiv pointed out in a comment, you should not add anything between the BEGIN/END WordPress comments as it might get whacked by a WP update. Your redirect has to come before the standard WP rules though, so add it at the top of the file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^hotel/ci/register /ci/register [L]
</IfModule>
# BEGIN WordPress
# ... These are the default, unchnaged WP rules
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
<IfModule mod_rewrite.c> and RewriteEngine On are duplicated which seems messy but you do need them, as your new rule has to go first so it processes the request before the WP rules do.
You don't need to modify the Codeigniter .htaccess file, the default one is all you need. It should be in the root of your Codeigniter installation, ci/.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
At this point https://example.com/hotel/ci/register will show the Codeigniter 404 page. If you have logging enabled (see config/config.php), and you watch the logfile, you'll see why:
ERROR - 2017-11-14 17:57:20 --> 404 Page Not Found: Hotel/ci
And here's the root of the whole problem. Since the initial redirect is an internal redirect (means the URL shown in the browser does not change), the URI Codeigniter receives to process is the one still shown in the browser address bar - hotel/ci/register. Codeigniter will try to handle a request like that in 2 ways:
Look for a matching route in application/config/routes.php
Or look for a controller named application/controllers/Hotel.php, with a method called ci;
In our case there is no Hotel controller, and no route to describe how to handle such a request, so boom, 404.
One simple solution is to create a route to handle this request:
$route['hotel/ci/register'] = 'register/index';
And now https://example.com/hotel/ci/register works!
Notes:
Setting your default route to register ($route['default_controller'] = 'register';) means that https://example.com/ci/ will also show register. I'm not sure if you want that? You might run into duplicate-content SEO problems if that URL shows the same as https://example.com/hotel/ci/register, so maybe you want something else, or a 404, there.
Make sure you remove your $route['404_override'] = 'register'; route;
CI base_url is not relevant for this problem, though obviously should be set. Depending on how you want your links to be I think either http://example.com/ci/ or http://example.com/hotel/ci/ would be right.
I am not quite sure what the purpose of this condition in your CI .htaccess is for:
RewriteCond $1 !^(index\.php|resources|robots\.txt)
The existing default conditions already skip files and directories which exist on disk. That's what the !-f and !-d conditions mean - "if the requested pattern does not match a file or directory on disk, then do the redirect".
If you have a robots.txt file on disk (in your ci/ dir), and someone requests https://example.com/ci/robots.txt, the !-f condition will fail, and the rewrite is skipped - meaning the request is handled without rewrites and robots.txt is returned successfully. Same for index.php. If you have a directory called ci/resources, and someone requests https://example.com/ci/resources, the !-d condition will fail, the redirect is skipped, and the request is successfull.
I'm not sure about your resources part, but maybe you can remove that condition completely.
If you don't need pretty Codeigniter URLs (I mean other than https://example.com/hotel/ci/register, this change won't affect it), and it turns out you don't need that extra condition above, you can get rid of the CI .htaccess completely to simplify things. To do that, just change the Wordpress RewriteRule to the non-pretty version:
RewriteRule ^hotel/ci/register /ci/index.php/register [L]
And delete your CI .htacces.
I think you are on the right path, try this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/hotel/ci(/.*)?$ /ci/$1 [L] # remove the register part
# so that it would be handled by CI
# also remove the "?" in front of hotel
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
keep your CI htaccess as it is:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
the last part is match your CI config.php to your new url model
$config['base_url'] = "http://example.com/hotel/ci/";
I don't thing this will be the great answer of your question but if i face the same problem i will use routes see the example code.
$route['(:any)/ci/register'] = "register";
what will the above code do (:any) means any word in first uri and after that you can defined any url you want i defined ci/register you can also do that like this.
$route['(:any)/register'] = "here_you_can_add_your_controller/function";
this will work if hit url like this.
http://www.example.com/any_word_you_want/register
it will hit your controller function. you need to echo something and it will show in your browser.
you can also defined the hotel word in your base url as #am05mhz shows in his answer but i don't thing that's a great idea because in future may you have 2 more words in your url.
Note : the above code example only work if your .htaccess give access of routs as you shows in your question the .htaccess is work for you. For full knowledge of routs please check the documentation of codeigniter URI routing
Use htaccess [P] flag instead.
Make sure the substitute (target) string will start with http://. Otherwise, it will treat the substitute string as an internal file path.
Check the code below.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/?hotel/ci/(.*)?$ http://example.com/ci/$1 [P]
# If you want rewrite any URI as long it has */ci/* in it.
# Use the following rule instead.
# RewriteRule ^(.*)/ci/(.*)?$ http://example.com/ci/$1 [P]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Also, you don't need to update CI's base url. Empty string will do.
$config['base_url'] = '';
Hope that helps.
Links:
https://httpd.apache.org/docs/current/rewrite/flags.html#flag_p
I am new to WordPress, creating the custom taxonomy for location in the my current URL
http://localhost/myproject/locations/us
i am need to change the URL like in that location place rename to my-project
i am trying to change the URL using Rewrite rule in ht-access file
RewriteRule ^my-project/us?$ http://localhost/myproject/locations/us [R=301,NC,L]
but its not working any one help me?
Custom .htaccess in WordPress site can bring unexpected results.
You may instead use WordPress' specific Rewrite API
Edit: if you need to use .htaccess insert your rules before the WordPress' ones.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^my-project/us?$ http://localhost/myproject/locations/us [R=301,NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
This is the final .htaccess code, i tested this solution here and it works correctly.
If this solution didn't solve your case maybe there is a problem elsewhere.
I have installed a wordpress site for a client.
The site works fine on local system as well as the test server but not on the live server. The domain is created as an Alias of an existing site. Homepage displays fine but internal pages show blank with a 500 internal server error in Firebug console.
For the past 3 days I've searched and applied all sorts of fixes to .htaccess, code etc but it doesn't seem to fix.
What I've tried:
Uploaded the code and database twice.
Generated .htaccess fresh using permalinks settings of wordpress.(there are no custom rules in my .htaccess)
Set php code to display all errors but there are none, only notices.
Talked with the server hosting guy and got the memory limit increased.
What I've not tried yet:
Persue the client to create a subdomain instead of an alias.
Please suggest any possible fixes. Thanks!
# 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
UPDATE: Issue Resolved: It was a memory issue on the server. Disabling a few resource-heavy plugins pointed me in the right direction.
Have you tried this...
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /put-the-alias-here/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /put-the-alias-here/index.php [L]
</IfModule>
# END WordPress
I have import on my local webserver a backup of a website made using WordPress but I am finding some difficulties with PermaLink configuration
The main problem is that if I use the permalink setted as Article Name I can see the homepage but if I click on the articles links into the homepage (to see the article) I always obtain the following message error:
Not Found
The requested URL
/wordpress35/2012/10/11/se-milano-avesse-il-mare-anzi-no-la-montagna-di-campiglio/
was not found on this server.
If I instead I use the Default settings for permalink (http://localhost/wordpress35/?p=123) I have no problem and I can access to the articles in my website
I think that this is a .htaccess problem. Can you help me to create an .htaccess file that solve this problem?
My actual .htaccess file is:
# 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
I need to use the URL format described as: http://localhost/wordpress35/my-article-name
Did you try creating a the wordpress .htaccess for your needs?
# 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
This should work if you didn't specify any change in the website's URL.
(If the homepage is still http://localhost/wordpress35/ )
I've got an url /nl/sunglasses which is a translated page by qtranslate. I want to change this to /zonnebrillen . I prefer not to change this in wordpress since the 'sunglasses' is generated by a plugin wp-ecommerce and hardcoded.
Can I use a mod_rewrite so that /nl/sunglasses will be /zonnebrillen. And how can I let wordpress 'know' to show the according page?
Cheers!
Here's some code I modified after getting WP to take query vars in the URL including "name" as a query var. I am including the "original" .htaccess file posted by regular WP install to show the context. I have separated the rewrites to avoid problems when WP updates, or when "certain admin functions" cause it to change. P.S. I didn't test this, but similar code works for a much more complex page redirect... so try it. Let me know if it doesn't work for you, I'll test it.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^nl/sunglasses/ /zonnebrillen [NC,L]
</IfModule>
# 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
Should work with WP 3.4+