RewriteCond not working in debian - php

I have a PHP script running on apache server (debian). The problem is the "RewriteCond" doesn't seem to be working while rewrite_mod is enabled. Just a couple of instructions in the .htaccess are working, and this is why I'm encountering errors through the routing process and the server keeps saying that some routes haven't been found.
IndexIgnore *
Options -Indexes
RewriteEngine on
RewriteRule ^(config/|config\.php) - [F,L,NC]
RewriteRule ^article/(.*)/? index.php?article&do=view&title=$1 [L,QSA]
RewriteRule ^thesis/(.*)/? index.php?thesis&do=view&title=$1 [L,QSA]
====================================================
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} $
RewriteCond $1 !^(index)
RewriteRule ^(.*)/? index.php?$1&route=true [L,QSA]
====================================================
RewriteRule ^me/? index.php?me [L,QSA]
RewriteRule ^home/? index.php?home [L,QSA]
RewriteRule ^layout1.php index.php?layout1 [L,QSA]
For instance :
domain/foo
It says foo not exist, But
domain/home
is working with no errors
EDIT :
Now it got a portion of my problem working, I tried domain/FOO uppercase like thas and it seemed to work! Why is it to be working with uppercase? What can I do to get this to work in lowercase as well ? The foo.php is into the folder
Thank you

Related

.htaccess mod rewrite works on WAMPP but not XAMPP

I am trying to write my .htaccess file so that all pages of the website (index.php, sports.php, team.php and about.php) appear as domain/index. team.php also occasionally takes in a $_GET variable which i am trying to show as domain/team/getvariable. I have came up with the following .htacces:
Options +FollowSymLinks
DirectoryIndex index.php team.php sports.php about.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R] # <- for test, for prod use [L,R=301]
#RewriteRule ^s/(.*)$ ./team.php?s=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
This meets all my requirements on WAMPP, however hosting the website using XAMPP behaves differently; the redirection to team/getvariable succeeds but throws a 404 error, the rest of it works well. You can also see that I have tried this one with a different approach but it behaves the same way as the current line. What am I doing wrong?
Solution
I changed the last line to
RewriteRule ^(.*)$ team.php?s=$1 [NC]
You are rewriting /team/variable to /team/variable.php. I guess this occurs your 404 error.
So I think you want to rewrite to something like /team.php?v=variable? Then this should work:
RewriteRule ^([^/]+)/([^/]+)/$ $1.php?v=$2
Why it works on WAMPP is another question...

mod_rewrite in .htaccess causing directories to lead to error 500

I've been modifying my website URLs in order to beautify them a bit, but I'm currently having an issue regarding to the site directories.
For instance, my links look like users/[user_id]/ instead of users.php?p=[user_id]. Everything is working well apart of the directories, as said above.
When I try to access, for instance, to www.mywebsite.com/js/, I'm facing an error 500 from the server, which, hypothetically, means that there is no file/directory with this name, because of the RewriteCond %{REQUEST_FILENAME} !-f and RewriteCond %{REQUEST_FILENAME} !-d line.
Here is the code I've put in my .htaccessfile:
RewriteEngine On
RewriteRule ^users/([0-9]+)/?$ /user.php?p=$1
RewriteCond %{HTTP_HOST} ^mywebsite.com [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/?$1 [L,R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ $1.php
RewriteRule ^([^/]+)/([^/]+)/?$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
# Error Documents Redirect
ErrorDocument 404 http://www.mywebsite.com/notFound/
ErrorDocument 403 http://www.mywebsite.com/forbidden/
ErrorDocument 401 http://www.mywebsite.com/unauthorized/
# Options
Options All -Indexes
Options All +FollowSymLinks
I don't really understand, as I just started working on this for the first time like a few hours ago, and I just start to understand the regex, and path formatting.
I hope you'll be able to help me, and through this, help people facing this issue too.
Regards
add this
RewriteCond %{REQUEST_URI} !^/(css|js)/
below
RewriteRule ^(.*)$ http://www.mywebsite.com/?$1 [L,R=301,NC]
please put this and check
and this after
RewriteEngine On
// having this rule in place we can remove the upper mentioned rule as apache will stop processing other conditions when see this rule
RewriteRule ^(css|jss)($|/) - [L]

Remove .php extension is not working

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

Rewriterule in Slim Framework getting Error 500

I have this problem, I'm running locally an application (PHP 5.3.5) and it works, but when I put it online it doesn't (I have PHP 5.3.6).
http://domain.com/ //works
http://domain.com/route //doesn't work Error 500
http://domain.com/index.php/route //works
This is my '.htaccess'
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
As you can see I only added this line RewriteCond %{REQUEST_FILENAME} !-d
I also tried with the original .htaccess but didn't work.
Any ideas?
I just try with Wordpress default .htaccess
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
And it works
This Worked for me! I know A lot of people are struggling with this. But i hope this works for you guys too. Good Luck
Also don't forget to add this in your virtual host file...
AllowOverride All
Rewrite rules
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]
Thats works but when you send paramters. it just goes to 404 error. Anyone know how to solve that issue.?

Using .htaccess to URL rewrite on windows

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.

Categories