I'm trying to send file from a rewritten URL.
Inside the .htaccess file I have:
RewriteRule ^foo$ foo.php [L]
In foo.php:
header("x-sendfile: ".$_SERVER["DOCUMENT_ROOT"]."/filesdir/test.txt");
When browsing to foo.php directly I see the content of the file, but when browsing to /foo I get 404.
I've tried to search the web but couldn't find any solution for this other than redirecting foo to foo.php
does anyone knows what's the problem and how to solve it?
I solved the problem.
In httpd.conf there was XSendFilePath directive which was a resolved symbol path while in the php there the "filesdir" was actually a symbolic link to the path in XSendFilePath.
I've add the symoblic link to XSendFilePath and now everything works well!
Related
So, I have the current file structure:
ROOT
-> /public
-> /user_views
user_handle.php
user_profile.php
user_feed.php
user_settings.php
.htaccess
As you see, the folder user_views contains a few of the possible views that the client could want to look at. What I am wanting, is for clients that insert the URL http://example.com/user/ to be directed to the page user_handle.php. This handle would act as a root file for all /user/ pages, and it would accordingly split into those pages through numerous $_GET requests.
So far, I have the following .htaccess, but it's not working...
RewriteRule ^user/ user_views/user_handle.php [L]
What could I do to get this to work, so that the url http://example.com/user redirects to the user_handle file in the user_views folder?
Thanks!
I'm not sure I fully understand your question, but it seems you would like to make user_handle.php located under public/user_views act as a "router" for the rest of you PHP files and have all requests to /user/ (e.g. /user/?page=1) be processed by user_handle.php.
If that's the case, your rule seems legit. The only thing I noticed (I might be wrong) is that your .htaccess is located outside the public folder. In that's the case, you need to include 'public/' as part of your rule.
I recreated the folder/file structure you described and it has worked for me using the following .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^user/ public/user_views/user_handle.php [L]
</IfModule>
Slight chance this is the problem, but you also might want to double check that mod_rewrite, which is the rule-based rewriting engine is enabled on your server/local environment. It should show up under 'Loaded modules' when you call phpinfo() in any PHP file.
Hope this helps.
Alright, so I'm really struggling right now, I've tried everything, read articles and tutorials but I still don't know why this doesn't work.
I've got an index.php file:
echo "some test";
if(isset($para)) {
include $para . '.php';
} else {
echo "there's no parameter";
}
So if the user views the page with the parameter 'home' (http://mypage.com/test/index.php?para=home), he'll get the correct page. That does work.
.htaccess:
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mypage.com$ [NC]
RewriteRule ^(.*)$ http://mypage.com/test/$1 [R=301,L]
RewriteBase /test/
RewriteRule ^([a-z]+)$ index.php?para=$1
But when I try to navigate using the rewritten link (http://mypage.com/test/home), the browser only outputs the included file and it completely ignores the index.php and its content.
Is there something wrong with my htaccess file? Or do I need to change some server configuration? Because I had a different htaccess file on a different webserver and it worked without any issues. But it didn't work on the webserver I'm using right now (sadly, I only have access to the htdocs folder).
EDIT: Just checked phpinfo, the page is running on PHP 5.3.28 on apache2.
Solved!
Problem solved. Adding 'Options -Multiviews' fixed the issue.
The hint here is:
The browser only outputs the included file and it completely ignores
the index.php and its content.
Try disabling mod_negotiation (Options -Multiviews) in the context where you want to do this remapping with mod_rewrite and within your script.
mod_negotiation is the most common reason "other" rewriting seems to be happening on your resources.
I had this setup:
images
image1.jpg
image2.jpg
header.html
about
index.php
image3.jpg
But going to MyWebsite.com/About gave it an extra slash on the end. I decided to go with the solution of creating a file called about in my home directory:
images
image1.jpg
image2.jpg
header.html
about
aboutfiles
image3.jpg
The problem is that now this file won't let me use .php:
<?php include('header.html');?>
It's not showing the header file. What can I do to make this work?
Your problem is that your web server does not recognize the filename "about" as a php document. You have three options
Use a ".php" extension on your page document, such as "index.php" which will run your php scripting.
Install a solution such as mod_rewrite that will translate urls such as /about to a file actual like "about.php".
Adjust your servers mime-type for php documents. Learn more about MIME types here. https://developer.mozilla.org/en-US/docs/Properly_Configuring_Server_MIME_Types
The first solution is the simplest and easiest, in any document you use PHP, the extension should be .php
About the mywebsite.com/about issue, it's more an Apache configuration issue. You have to tell Apache that index.php should be an index file.
First, you can configure your Apache (or IIS) to use whatever Extensions to process PHP-Code.
You can define .ThisIsAPHPFile as valid extension, if you want.
However, Directorys are always reflected with a trailing /: www.example.com/dir1/ (Browsers not always showing the trailing /) while files have an extension: www.example.com/dir1/index.html.
So, from what i see, you want to use www.example.com/about but showing the about-FILE ?
Therefore you can use rewrite Engines of your Webserver. Either have a look at mod-rewrite (http://httpd.apache.org/docs/current/en/mod/mod_rewrite.html), when using Apache, or (one possibility) ISAPI-Rewrite (http://www.isapirewrite.com/docs/), when using IIS.
If you edit your virtualhost directive in your apache conf file, you can add the following:
DefaultType application/x-httpd-php
This will tell apache to send web paths that do not end in an extension to render using the php engine.
Therefore, /about would act as if it was about.php. Another potentially more useful approach is to name the file about.php on the server, and allow referencing it without the .php in the url. For this, you would configure it the opposite way.
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]
I have a list of PDF [myfile.pdf] files on a folder/dir called example.com/uploaded/downloads/
I need a user to download or view on the page a pdf file, however I do not want them to see the uploaded on the url, which is the best way to do it?
so users can click a link example.com/downloads/
I had a .htaccess code (since im not good at it) it got me no where
RewriteRule ^downloads/([A-Za-z0-9-]+) /uploaded/downloads/$1 [L]
I have tried PHP header('... application/pdf'); not good either.
PLEASE NOT: example.com could change directory aswell e.g. example.com/new_design/ therefore the dir would be example.com/new_design/uploaded/downloads/ and users should be able to see example.com/new_design/downloads/
TIA
Make sure you have the RewriteEngine turned on and try this slightly modified pattern.
RewriteEngine on
RewriteBase /
RewriteRule ^downloads/(.*)$ uploaded/downloads/$1 [L]
If you are still having trouble, try looking at the Apache log files. They may indicate a problem with permissions or the file path. The log file is usually located in /var/log/apache2.
I've had to move from testing on the live server, to testing locally on a virtual apache server. I've installed XAMPP just fine, downloaded and installed the wordpress files and the database. Everything looks great! The local version of my homepage is identical to the live version. There's only one problem: the homepage is the only page that works. When I click on one of the links i.e. the "about" page (http://localhost/wordpress/about/), I am redirected to the xampp control panel (http://localhost/xampp).
I have a good feeling this has to do with a problem with the "pretty links"/mod_rewrite rules. I made sure I brought over the .htaccess file, and it contains the rewrite instructions. The wordpress database has the proper permalink structure, and the httpd.conf file has the "RewriteEngine on" and the "FollowSymLinks" directives enabled. There has got to be some sort of rewrite problem here, although I am not ruling out something else stupid I might have done. Thanks for all your help!
-E
*Here is what the .htaccess looks like:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
In the httpd.conf, change the
DocumentRoot "/path/to/your/app/wordpress"
also
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/path/to/your/app/wordpress">
This should work, the path is absolute.
And do you have load the:
LoadModule rewrite_module modules/mod_rewrite.so
in httpd.conf??
If your server version works with a domain name, i.e: http://domainname.com is equivalent that http://localhost/wordpress the rewrite rules will be differents. post the rules here.
The problem is that wordpress does not believe in relative paths for some reason. There is an assumption that wordpress is running from the server root not a directory under the root (e.g. /var/www/wordpress will not work, but /var/www/ will).
The problem is with the .htaccess file they provide. It should re-write it to index.php and not /index.php. Change that line in your config and it will work.
What happens is that it tries to actually go to the default document root (in my case /var/www/index.php, which does not exist since I am using http://localhost/worpress which is an alias for ~/projects/worpress). You can check your error log and it will tell you where it is trying to look for the index.php file (which will return a 404 error).
I can go on a rant about how stupid it is that they do that and how bad the whole software design of wordpress is. But I will spare you that :).