Good day. I have a problem with links in my application. I want to use 'pretty-urls',so i want to all my links look like 'www.sitename.com/controller/method'. So i want to print my all my links through one function,which would look like
function link($url_segments) {
if(mod_rewrite_is_available)
return BASE_URL.$url_segments;
else
return BASE_URL."index.php".$url_segments;
}
But i can't understand how to detect if server has rewrite module enabled. I have found 2 solutions:
Place in config some variable(like codeigniter does) like
$config["index_variable"] to use inside my function,but that means
that all my clients will need to change that line in config when
installing application on hosting
Use function to detect mod_rewrite,like apache_get_modules,but like
i understood it can be not avaibale on some hosting,and what if
server will be nginx?
So i want to know,how to detect that and print my links.
Thanks everyone for help.
Can you just provide the .htaccess to your clients so that, when you upload the files, it turns the rewrite mod on?
This can be very tricky and hard, personally, I would go with the fallback approach.
Look at apache2handler's loaded modules (via phpinfo()) to see if mod_rewrite is there
Try sudo apache2ctl -t -D DUMP_MODULES to see if mod_rewrite is loaded
Try to use a .htaccess file to see if everything is working.
Try to determine the server software used, and parse the conf file for the server
Use worst case of no mod_rewrite is enabled, and then enable it manually after the software has been installed.
Related
As you can see, it gives me a weird view. I use apache+php5+mysql for my wordpress, and everything seems to work right during installation of Wordpress. But it just gives me such a strange scene.
Has anyone seen similar problem as I do? When could be the reason for this?
Can't say for sure without visiting the site, but it looks like you didn't add index.php to DirectoryIndex in your httpd.conf file (for Apache, or whatever the equivalent is in whichever server you're using)
I am not sure - pic resolution is low but it looks like the directory contents. make sure php is (a) installed (b) enabled on the directory (c) after you make changes to the server config, restart it (d) php files are set to execute php interpreter
All I want to do is be able to see a PHP file from the root without it going through the rewrites (thus our custom CMS).
Here's what I've done:
In my httpd.conf, I've commented out the call to load the mod_rewrite module.
Next, I've removed the .htaccess file from the root as it had the rewrite rules in it.
I've rebooted the server.
I've searched through phpinfo() and there are no "rewrite" strings to be found
The problem is that the server still rewrites and the request passes through our CMS.
I'm using XAMP (PHP 3.3.1, Apache 2.2.14)
What am I missing?
maybe cache problem in your browser? because a similar thing happened to me and deleting the cache solved it.
Leave it to the details... I was trying to access my_file.php on the root. However, the filename was actually my-file.php (dash vs underscore).
The page I was getting was a 404, which went through the CMS. When I access the proper file, the one with the dash, I get what I'm supposed to.
I appologize for the waste of time :)
I want to start learning php, I install apache 2.2 and I want to run my first.php file, I look for www folder in the installation folder of ApacheSoftwareFoundation but I couldn't find it.
here's the files in the apache
I tried to put my php file in htdocs but it doesn't work , can some one help ?
Edit
Doesn't work means when I make http:localhost/first.php , returns Unable to connect
Now the apache is running, when I open htt'://localhost/
returns "it works"
but when I open any php file, it opens as-is ?!
You'll need to check a couple of things...
Make sure the Web Server is running ,either the service
or the program, is running and that you have the correctly configured the Virtual Directories.
If the web server just outputs the
content of the .php file, it could
mean that you don't have mod_php
installed. Meaning the server does
not have the Mime type registered so
it will just try to treat it as a
text file ...
And as your on windows you might consider using something like XAMPP. It gives you a Full Working AMP (Apache Mysql Php) Stack with one install and a easy control manager to start/stop the servers. Other wise do a couple of Google searches on how to install the php module for your Web Server on Windows
Update
To start the server try executing the executable bin/httpd.exe .
Now the apache is running, when I open
http://localhost/ returns "it works"
but when I open any php file, it opens
as-is ?!
A default installation of Apache on windows does not include the necessary modules to run PHP. After installing Apache, you must either:
Install PHP separately and follow the instructions described here to configure Apache to use the installed version of PHP to serve .php files. I've been through this and took me hours to get every thing to work.
Recommended for you: uninstall Apache; install WAMP instead.
if you look in your httpd.conf file you will find the default root directory, it doesnt have to be called www. It is the htdocs by default.
error 500 covers a whole host of things. from compile error, to permissions.
Have you put a simple file of
<?php
echo "test";
?>
As your test php page to rule out other issues?
You need to:
Construct your URI correctly: http://localhost/first.php (with the //)
Ensure that Apache is running
all files in htdocs can be referenced from outside
Just put a basic file named index.php
and visit site http://localhost/
In general type in http://localhost/filename
You say that you get a connection error when you try to go to your webpage. Since it looks like you're using Windows Vista or 7, make sure you're running Apache as an administrator; it can't bind to port 80 otherwise. Also check that other programs like Skype aren't binding to port 80. If you still can't find the problem, check the error log. (logs/error.log by default I think)
The problem is that Apache was installed but not started
If you are using xampp start it and then start apache through control panel
for others look for similar instruction
I tried researching this question on my own for awhile, but can't seem to pinpoint the solution. I'm working through the CakePHP Blog Tutorial, and at this section: http://book.cakephp.org/view/1536/Creating-Post-Views
I create the index.ctp file with the code given by CakePHP. Then, when I open the index.ctp file in Safari, it simply shows the code given by CakePHP. It doesn't not render any HTML, nor does it pull the blog data from the database.
If I switch the extension from .ctp to .php, it renders HTML but it does not pull blog data from the database. My database is connected and has the correct information. I think there is an issue with the .ctp extension? Not sure. Has anyone else run into this kind of issue?
First, try this url:
http://localhost/posts/index
Second, you may have not mod_rewrite enabled in your development environment.
On ubuntu for example you can enable it with like this:
sudo a2enmod rewrite
(EDIT: restart apache afterwards)
Third:
Check your .htaccess, you need mod_rewrite to be enabled. Also check the tutorial/cakePHP documentation to find out if you missed any step concerning .htaccess and the Rewrite Rules.
RedEye,
call it the way like tacone wrote
make sure the file is in the correct path according to the conventions
make sure your server process has correct access rights for the file under concern
Please make sure the AllowOverride is set to All (instead of None) in your sites-available/default file.
Using CakePHP 1.3, I have the following layout:
/srv/www/_cakephp13/
/app/
/cake/
/plugins/
/vendors/
etc...
/srv/www/htdocs/
/cake_app/
/other-dir/
... where htdocs is the public directory, and I have moved webroot of my app to be cake_app above... Which appears to be almost working. (After customizing webroot's index.php).
When I access http://devserver/cake_app/, I am able to see the default "Home" page controller/view (which I have customized, so that appears to be working).
But when I access http://devserver/cake_app/controller/view I am receiving 404 errors.
Is is possible to run a Cake App in a sub-directory of a site root? How can I get this working?
Ideally, I don't want to edit Apache conf's... If I can fix this with Cake configuration or htaccess files, I'll be much happier.
You should verify that .htaccess is being run and that the rewrite module is on and working.
You will need to have mod_rewrite enabled on Apache. To check if it's on, make a page that just does this:
echo phpinfo():
Grep on the text "loaded modules". Make sure mod_rewrite is listed there. If it's not, you can either add it to apache's configuration, or you may need to install it (depending on your original installation method and whether you included that module).
If you can't get mod_rewrite running, you can still use cake without it (the URL will just look like index.php/controller/action/etc). Check out http://book.cakephp.org/view/333/A-Note-on-mod_rewrite for more info. Specifically,
If you don't want or can't get
mod_rewrite (or some other compatible
module) up and running on your server,
you'll need to use Cake's built in
pretty URLs. In /app/config/core.php,
uncomment the line that looks like:
Configure::write('App.baseUrl',
env('SCRIPT_NAME'));