Im having a problem setting up mod_rewrite. Im using localhost and is on ubuntu.
I already enabled mod_rewrite and also changed the AllowOverride from None to All.
My .htaccess is as simple as this.. since it's not working I wanted to know if it's still not working in its simplest form:
RewriteEngine on
RewriteRule ^sample.html$ sample1.html
When i write sample.html in browser it says "not found"
Related
I have a QNAP NAS with Apache correctly installed. Some pages are linking fine except for ones using any RewriteRule. All other pages are linking correctly to mysql and displaying fine its the ones with any RewriteRule, these are showing up as a 404 error like this:
The requested URL /share/CACHEDEV1_DATA/Web/clients/hembury4x4/couk/view-sitemap.php was not found on this server.
URL = http://192.168.1.210/Web/clients/clientname/sitemap.html
FILE= http://192.168.1.210/Web/clients/clientname/view-sitemap.php
My rule is quite simply: RewriteRule ^sitemap.html$ view-sitemap.php [NC,L]
I have copied all the site files from my computer where the redirect was working perfectly. What do i need to add on my htaccess file?
Thanks in advance
First, apache should have rewrite module. It should present in the output of httpd -M command.
Then you should allow .htaccess files. This can be made by adding AccessFileName .htaccess directive (if it's absent) to your httpd.conf file. Also check you have this section:
<Directory />
AllowOverride All
</Directory>
I am on a VPS running Ubuntu 14.04 x64, and I have enabled mod_rewrite.
This works (i.e. correctly redirects to testfile.php):
RewriteRule ^othername$ testfile.php
But this doesn't (gives me a 404 error, saying "The requested URL /testfile was not found on this server"):
RewriteRule ^testfile$ testfile.php
So I essentially cannot redirect a URL to a file of the same name but with a PHP extension. The two examples are both working locally with MAMP.
What could be causing this issue?
As anubhava said, you just have to add Options -MultiViews at the top of your .htaccess.
I have a very simple rewrite rule. My entire .htaccess file is as follows:
RewriteEngine On
RewriteRule ^login/([a-zA-Z0-9-/]+)$ company-page.php?company_url=$1
RewriteRule ^login/([a-zA-Z0-9-/]+)/$ company-page.php?company_url=$1
This is perfectly run on locally Wamp server but not working on online server. It display following error.!
The requested URL /EZsample/login/mereco-technologies/ was not found on this server.
Can anyone help me!
if you are using a VPS please use this article,
1.Make sure u have enabled Mod_Rewrite ?
2.Made the changes in the virtual host configurations
https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite
This line of code helped me solve a very similar issue:
Options -MultiViews
My application worked with .htaccess when it was on localhost
When I uploaded the application to the server, the .htaccess is not working.
Through phpinfo(); I noticed that mod_rewrite is loaded under apache2handler.
I suspect my .htaccess rule maybe wrong, so I tested with
http://www.webune.com/forums/viewtopic-p-62.html
but it still didnt work, the 404 page is showed.
What should be the valid reasons for above problem?
Thank you so much for your help :)
I would guess that AllowOverride is set to None or something that is preventing you from controlling mod_rewrite within an .htaccess file. You're going to need to be able to modify Apache's config to change that.
Here's how you test it: How To Check If mod_rewrite is Enabled in Apache
If you have access to your Apache config files, look at http://httpd.apache.org/docs/2.1/howto/htaccess.html.
Check the AccessFileName parameter if it is .htaccess. It should be by default. If it is, then it is a problem with the site configuration. Refer to Jonathan's answer for that solution.
I'm trying to port a PHP site developed by another coder (who is no longer around) and I'm having a problem with the Apache Rewrite rules which are prompting a file download on the target server. I'm sure this is a simple problem, but I'm having some difficulty Googling an answer. I'm running on a (dedicated) Ubuntu Server with a standard installation of Apache and PHP5 and porting from shared a shared server where everything runs fine. No site files have been altered during the port.
The .htaccess file contains this code (only)
# Use PHP5 as default
AddHandler application/x-httpd-php5 .php
Options -Indexes FollowSymlinks
RewriteEngine on
RewriteRule ^html/(.*) /index.php?init=site\/$1\/$2\/$3\/$4\/$5\/$6\/$7\/$8\/$9
RewriteRule ^mykart$ /index.php?admin=true
RewriteRule ^mykart/$ /index.php?admin=true
RewriteRule ^mykart/(.*)$ /index.php?init=admin\/$1\/$2\/$3\/$4\/$5\/$6\/$7\/$8\/$9&admin=true
When I try to open the file http://www.mysite.com/html/#home the browser attempts to download the (index.php) file instead of displaying it, with the message
"You have chosen to Open
[dialog shows blank space here]
which is a: application/x-httpd-php
from....
"
I guess I must have missed something in either the PHP or Apache configuration, but what?
EDIT: To clarify, the server is running Apache2 and has several, functioning, PHP sites on it. Furthermore if I delete the .htaccess file and run a simple phpinfo display page everything runs fine, so it's not the execution of PHP per see.
I suppose that the MIME type application/x-httpd-php5 is not valid. I’ve tried it on my local machine and it caused the same behavior.
Have you tried application/x-httpd-php instead?
Looks like an Apache config issue, of course I could be wrong. Have you checked httpd.conf for the following lines:
# Add index.php to your DirectoryIndex line:
DirectoryIndex index.html index.php
AddType text/html php
I had a similar issue. Browser attempted to download links from php website, instead of loading them.
It wasn't Php interpreter issue for me, it turned out to be misplaced .htaccess file. However, I didn't realized that disabling the htaccess file solved the issue for hours, due to browser cache.
So, don't forget to clear your browser caches! And restart Apache.