Putting a php file in cake php - php

I have a cake PHP project in which I need to put a php file in root folder like 'faq.php' and link it somewhere in the project. But as soon as I point to the url it redirects me to the index page. I don't want to dig deeper just want to add an static link. Here is my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

If you want to add any non-Cake content that needs to be accessed via the web browser in CakePHP you need to put it in the webroot folder as Cake's htaccess setup rewrites all other URLs. (If you're using the older CakePHP 2 the webroot folder is in app).

You need to put it in the app/webroot directory.

You can put any php and call it from wherever you want.
In your Templates Dir you will have an Element Dir - in there create a FAQ dir and in the FAQ dir create a file called faq.ctp.
Then in the faq.ctp just drop in your php code, same as you would if writing in raw.
To call you can just call the element from whichever model you are in like so:
<?= $this->Element('FAQ/faq') ?>

Related

How can I change the URL path to folder in server using htaccess

I want to change the URL path to a folder using .htaccess like the format below:
http://example.com/src/home/
To
http://example.com/home/
Any Help ?
Using .htaccess:
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^home/(.*)$ src/home/$1 [QSA,L]
If I should design the structure, I would do it like this:
/
/src/
/src/public/assets/css/all.css
/src/public/assets/js/all.js
/src/public/index.php
/src/public/.htaccess
/src/app/ <= All you classes, php files and functions
Set documentRoot to /src/public
Your index.php is now your entry point and you can load all your classes, setup a MVC pattern or anything you like.
All files that you use in your project in referenced by the server root / all assets that the browser is supposed to use, like css and js you put those in the public.
If you want you images to be secure, you could load them via a php file that takes them from outside the public folder.
Hope this all makes sense?

How to create fake PHP directory that mapped to another PHP directory?

For example, I have a folder web.com/app/resource/css/ and from browser perspective I want the user to be able to access this folder via url web.com/css/ instead of web.com/app/resource/css/. How do I accomplish this with PHP?
Put this in your .htaccess file:
RewriteEngine On
RewriteRule ^css app/resources/css/ [QSA,NC,L]

Codeigniter run external PHP Script in a separated Folder

I have a problem with Codeigniters Security.
My Codeigniter Installation has the Application Folder, System Folder and a Assets Folder.
In my Assets Folder there is a Third Party PHP Script.
I want to Call this Script: DOMAIN/assets/FOLDEROFEXTERNALSCRIPT/EXTERNALPHPSCRIPT.php
Is there a option that i can call this File over the URL without a Controller?
I hope you have removed index.php from your url's which is done by either adding the below rewrite rules in the .htaccess file at your DOMAIN root directory, or by adding these rewrite rules in the virtual hosts.
Below rule means, to rewrite every url to index.php?params except if the current url contains "index.php or assets in it", now you can put any static content or even core PHP scripts in this folder to be access directly, with having CI in picture.
In your .htaccess file just add "assets" folder in the bypass rule, along with index.php
RewriteEngine on
RewriteCond $1 ^!(index\.php|assets)
RewriteRule ^(.*)$ /index.php?$1 [L,QSA]

Wordpress url rewrite on subdirectory

I have a wordpress install which has only two custom post types ( blog and howto ).
The blog is located in a directory inside root folder where also are few html pages, like this :
To access a certain custom post type from html files i have an href to wp/blog and another one to wp/howto.
The problem is that i want to jump that wp so my url will be like localhost/blog instead localhost/wp/blog.
I tried with
RewriteEngine On
RewriteRule blog/ /wp/blog/
RewriteRule howto/ /wp/howto/
in .htaccess from root directory, it shows me the blog template, but only 404 page error and i have no idea what should i modify to get the wordpress posts.
PS : Sorry for my english and for my blurry message, deadline's coming and i have no idea what should i do to skip that folder.
1) in your dashboard, go to settings -> general and make sure
a) wordpress directory -> http://mydomain.com/wp
b) site address -> http://mydomain.com
2) move your index.php from subdirectory to the root (MOVE, don't just copy)
3) edit your index.php to read
/** Loads the WordPress Environment and Template */
require('./wp/wp-blog-header.php');
where "wp" is your subdirectory
4) delete any .htaccess file in the subdirectory
5) add this to your .htaccess in the root
# 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
Under this setup, your wordpress installation will be located in /wp/ directory. Visitors will visit your site using http://mydomain.com.
If you want to have a good read-up on everything so you know exactly what you're doing, read this https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory
If i understand you correctly - all the wordpress system files are inside the "wp" folder.
if that is the case all you need to do is to drag them out to the main folder and the problem would be fixed by itself.
As far as the post types (blog/howto) if those are post types inside the wordpress system the are not effected by real folders but by something call Wildcard DNS - which is a method of linking url's to content by values inside the url. this means that the folder does not have to exist inside the server but just in the system.
For solving your issue i recommend to just, as i said before - drag all the files from inside the folder "wp" - outside of it.
And after that you will need to log in to the database with phpmyadminor any other client you have and go to:
A) choose wp_options
B) Look option_name for siteurl and remove the "wp" from the url. (if it's http://sample.com/wp change it to http://sample.com)
C) Look option_name for home and do the same.
Edit:
Try this:
in your root directory (the parent of "wp"), open the .htaccess file and add inside mod_rewrite.c:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?YourDomain.com$
RewriteRule ^(/)?$ wp [L]
change the YourDomain.com to your real domain.
this should work :)
source: ~here~
im looking for a solution just like this. People keep on going around the question. What you want is for the custom posts to look like they come from the route mysite.com/todo/have-a-nice-day mysite.com/blog/todo/instead of mysite.com/blog/

How to access folder via browser if codeigniter project exists?

I have codeigniter project lets say example.com. In my public_html folder on my server, i created a folder called test and i want to be able to access some file via the web using example.com/test/somefile.php
Since i also have a codeigniter project in the same public_html directory, i always get a codeigniter page not found error when i try example.com/test/somefile.php.
How can i basically tell my server or codeigniter project that the folder "test" is not part of the codeigniter app?
In your .htaccess at the root of public_html, you probably have something like this for routing everything through index.php:
Example taken from the CI user guide: http://codeigniter.com/user_guide/general/urls.html
RewriteEngine on
# If the path doesn't start with one of these...
RewriteCond $1 !^(index\.php|images|robots\.txt)
# ...send the request to index.php/REQUEST
RewriteRule ^(.*)$ /index.php/$1 [L]
Just add "test" to the pipe delimited group, or whatever you need to do to allow access to the directory with your configuration:
RewriteCond $1 !^(index\.php|test|images|robots\.txt)
# ^^^^
Without this CI requires index.php in the URL - there's no way to actually have your Codeigniter app itself redirect, rewrite URLs, or block access to the /test directory, it's generally all done through an .htaccess file.

Categories