I have have turned mod_rewrite on in a windows machine and created .htaccess in the root directory of my website, now after i wrote FAIL in it it gave me an internal server error then i replaced the code with this
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]
I am trying to remove .php and make friendly URLs, when i am tring to load index without using .php it is giving me a 404 Not found error i have restarted the wamp server several times and the same problem. Can somebody help me here.
Thanks in advance
I have changed the .htaccess to this
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
and it worked just in case somebody faces the same problem
Remove the line RewriteCond %{REQUEST_FILENAME}.php -f. It is unnecessary.
Related
I know what this error is, but I'm sure it has something to do with my recent change of .htaccess or something missing from it. I added a few lines of rewrite code to change "something.php" to "something" - it worked fine. When testing my website online for the last few stages of development, I wanted to see what type of errors I'll get by attempting to access folders, and files - 404, 403, 401 etc.
Lets get to the point! When I entered ....com/press or ....com/press.php it will take me to the page as expected. When I enter ...com/press/ I get a 500 error - yes it has a slash, but shouldn't I be getting a 404 error? I say this because the file press.php exists, but not the folder ...com/press/ - it doesn't even show my own custom error page!
After taking a look at what I put in this .htaccess file, I also want some additional help with .htaccess. Index should be index alone, the server shouldn't accept .php even if it is, if you know what I mean!
Thanks in advance
Code in .htaccess:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]
Modify your rule as:
ErrorDocument 404 default
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
Index should be index alone, the server shouldn't accept .php even if
it is
You can use this so that if they using the php extension, it will redirect.
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /(.+)\.php
RewriteRule ^ %1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)/?$ /$1.php [L,QSA]
I am trying to remove the ".php" on my website. I have changed the .htaccess file based on the documentation provided in the dreamhost wiki to the following:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]
However, this does not work on the site. For example this code does not work:
link
It shows the following error:
Not Found
The requested URL /jimmyvosler.com/public/about.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
This works (but still displays the .php at the end, which is what im trying to fix):
link
I don't understand what is causing this, especially since the error even points to the correct place. Is there a setting I need to check on my admin tool?
Try this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Here is the solution for anyone else that has the same trouble. I added this to my .htaccess file. This solution came from dreamhost support and was linked from this website: http://eisabainyo.net/weblog/2007/08/19/removing-file-extension-via-htaccess/
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Try this:
Options All -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ $1.php [L]
I found a lot of tutorials and questions regarding to removing the .php extension in the URL. I have tried a lot of examples and until now it is still not working. This drives me crazy. I also want to put trailing slash at the end of the URL but first I would like to achieve this first. Currently I have tried this which is some of my solutions:
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L]
and also this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Nothing is good. I am working in my laptop using windows 7, and using XAMPP. I simply created my .htaccess file and put it in localhost/myFolder. When I run in the browser, depending on my solution, (i) some times I got page not found, (ii) sometimes server internal error. Also when I run for example localhost/myFolder/index the URL will be redirected to localhost/index without myFolder. I wonder why is this happening and hope somebody can give me links or solutions because I tried so many of them. Thank you in advance.
The following works fine for me:
RewriteEngine On
RewriteBase /myFolder
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*[^/])/?$ $1.php [L]
Try this code in /myFolder/.htaccess for hiding .php extensin:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/myFolder/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
A solution for your problem:
Options +MultiViews
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/myFolder/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
I just replaced your - sign in multiviews and it started working on my localhost
I've a question, I'm developing a webservice for a specific app.
Last week I transferred my back-up from server1 to server2, since that moment my .htaccess won't work anymore.
The url for my webservice is:
http://apps.holtesdesign.nl/inholland/apiv0/
This url works fine, to load the bugreport module:
http://apps.holtesdesign.nl/inholland/apiv0/bugreport.php
But the url was supposed to be:
http://apps.holtesdesign.nl/inholland/apiv0/bugreport
When you'll open the last url, you'll see that it will result in an internal server error.
Do you know how it's possible?
My .htaccess looks like:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
The server is running on CentOS, and I've already checked if mod_rewrite is functioning...
I hope you can help me guys!
Cheers,
Jelmer
This will fix it:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1\.php
If it doesn't work correct the settings of your Wamp Server:
Left click WAMP icon
Apache
Apache Modules
Left click rewrite_module.
This will hide the trailing slash and hide .php in root & sub directories.
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
Working Concept for me:
# Options is required by Many HostSevice
Options +MultiViews
RewriteEngine on
# For .php & .html URL's:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Use this code in Root folder of your website in .htaccess File : Example
offline - wamp\www\YourWebDir
online - public_html/
Important Note : If it doesn't work correct the settings of your Wamp
Server: 1) Left click WAMP icon 2) Apache 3) Apache Modules 4) Left
click rewrite_module
try this.. it works! :)
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
I want users to be able to go to /foo and have /foo.php displayed. A quick search on Google came up with this:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
For some reason, however, this doesn't work. I keep getting a 404 error, even though I know the .php file exists. I searched and searched for an answer, but it seems to work fine for everyone else.
I commented out the other rules, by the way, so nothing is conflicting with this.
Any ideas?
This is what you need:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Maybe you need to add the directive AllowOverride All in your apache configuration or maybe you need to add RewriteEngine On at the very beginning of your .htaccess file
You need this rule:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /$1.php
I found the answer! Apparently this is a problem with 1and1's server configuration. This article explains the problem: http://tips.webdesign10.com/web-hosting/why-you-should-never-use-1and1-com-hosting
The first comment also happens to be the solution. Here's the rule that works:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]
alternatively you can use apache's MultiViews option:
Options +MultiViews
You get this issue when you use .htaccess in a subfolder. Fix it by using full paths from the web root in your .htaccess file. For instance, in the folder http://www.mysite.com/test/ your .htaccess file would look like this:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ /test/$1.php
-not tested, might need tweaking-