htaccess file to make the clean url - php

I am using wamp server which consists of my project folder testCase which consists of few php files
testCase
- view.php
- add.php
- delete.php
- .htaccess
In the .htaccess file I have code like
RewriteEngine on
RewriteRule ^view?$ view.php
I am trying to run my project with url as "localhost/testCase/view" rather than "localhost/testCase/view.php" which results as Not found
I have found many tutorials regarding this htaccess in stackoverflow. Since I am a very beginner to programming, I could not fix this issue. Can anybody please help me. Even I get down vote or duplicate question I am eager to fix my issue.
Thank you.

You want to remove .php extension,
Try below rule,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+?)$ $1.php [QSA,NC,L]
Above will work for all your php files in testcase directory.

Related

my rewriterule's are not working correctly in the htaccess file

Im trying to create pretty urls for a site im currently working on but each time i navigate to the pretty url it tells me the page dont exist, could someone take a look at my code and see what i am missing or doing wrong
I have watched tutorials and searched online for written examples which is how i come up with the code i got but i just cant seem to get it to work
Here is the code
RewriteEngine on
RewriteRule ^sub_cat/([0-9]+)/([0-9]+) view_sub_cat.php?tcid=$1&scid=$2 [NC,L]
Thanks in advance
Try adding these two lines of code to your .htaccess file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Hosting several websites on wamp with laravel breaks the routes

I'm currently hosting several applications on a quite out-dated wamp version but that's not really the case. Everything is working fine on that part, besides my laravel application.
My .htaccess in the www folder looks like this;
RewriteCond %{HTTP_HOST} ^sapdfr.org$ [NC]
RewriteRule ^((?!sapdfr/websitev3).*)$ /sapdfr/websitev3/public/$1 [NC,L]
The thing that's strange, is that the first page is working but when I'm going deeper into the website, it just totally breaks. I've been trying to rewrite these rules but I'm seriously mindblown about all the possibilities. Any help will be greatly appreciated since I'm entirely lost here.
Maybe a silly question but have you try that ? :)
Laravel includes a public/.htaccess file that is used to provide URLs without the index.php front controller in the path. Before serving Laravel with Apache, be sure to enable the mod_rewrite module so the .htaccess file will be honored by the server.
If the .htaccess file that ships with Laravel does not work with your Apache installation, try this alternative:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
and then just redirect your domain to the laravel public folder

Remove file extension on url

Good day!
Got a lot of questions here but i guess i can't ask it all at once so i'll start with the problem i am facing now.
So, I am new to .htaccess and I don't know how or if it is possible to remove the file extensions on url, like for example I am accessing my home page in this url "www.sniper.com/home.php", so the question is clear. Is it really possible to use .htaccess to remove the file extension so that when you are at homepage the url will look just like "www.sniper.com/home" ?
To remove .php extension
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

.htaccess file not working with certain servers

Hello and thank you for taking the time to help me solve my problem. I like to build all of my web projects using a simple MVC Framework I have created along my travels. I seem to be having a problem getting the .htaccess file to work correctly on specific servers.
For example...
If you go to:
http://thomsonbrothersindustries.com/northside/ and attempt to access a page (right now only "About Us" is functional - http://thomsonbrothersindustries.com/northside/about) but as you can see the "about" page just directs you to a 404 Error.
Now, if you go to: (the same site, but on a different server)
http://ericzdisposal.com/northside/
http://ericzdisposal.com/northside/about
everything works fine...
Here is the .HTACCESS file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]
My privileges are limited on the server that is currently not working and I'm still working on getting better access to domain tools, but in the meantime I'm just trying to get a better idea of the problem and hoping there might be an easy fix in my future.
In addition to what #bigman suggested, make sure that AllowOverride directive setting is not very restrictive for your website directory. For mod_rewrite to work in .htaccess, you need to set AllowOverride FileInfo, but for testing purposes, you can set AllowOverride All.
Looks like adding the directory into the .htaccess file did the trick!
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ **/northside/**index.php?rt=$1 [L,QSA]
I didn't realize this was important because on the other server it did not matter
Thanks all!

URL Routing method for core php

I have web site in core php and I want to make my SEF URL.
In my web site for transferring control from one page to other i have used something like
header("Location: edit.php?id=12");
I read one article but couldn't get it how to implement it.
Link of article
So how i can make url to read like "mysite.com/usr/edit"
I read lot on google i got the idea that i need to do something in .htaccess but i dont know what needs to do with url in php so i dont have to change major code in site.
Thanks in advance.
You can do it with the .htaccess code given below:
RewriteEngine On
DirectoryIndex index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
after creating .htaccess file with above code. You will have all the stuff after the file name ex. "/usr/edit" in the GET parameter $GET['url']. After that you can do anything.
Here is the working example of my MVC framework: https://bitbucket.org/ManthanB/my-framework/
You can contact me for further information.

Categories