how to change default page index.php to url - php

i have my .htaccess file here..
RewriteEngine On
RewriteBase /faith/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]
RewriteBase /faith/ is the main folder on my local... but my problem is when i upload it in the cpanel i dont have any idea on how to use the url as my index.php .. i tried to search for it and it says that i need to change the rewritebase in a url.. but that doesn't seems to work cause what i want is my index.php will be a url.
my login page is index.php
and i want it to become sample.com so whenever i search it the only thing that i need to do is to type sample.com

Just add this line at top of your .htaccess:
DirectoryIndex index.php
This will load index.php by default when you visit http://example.com

your script seems ok in .htaccess file, you just need to use the redirection file name just like you are using index.php , you can use sample.php overthere.
RewriteEngine On
RewriteBase /faith/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ sample.php?uri=$1 [QSA,L]

Related

.htaccess Hide php param keys from url but dont change physical path

I am looking for a solution to hide param keys from my url
for example /page1.php?city=Lahore
I want it to rewrite as /page1/Lahore
but the most important thing is Lahore is not a directory exist on server I want it to point to same file page1.php just rewrite url externally
thanks
create an .htaccess file from the root and paste this code
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule ^page1/(.*)? /page1.php?city=$1 [L]
or you could also put it in your website apache conf file.
try this code
for .htaccess file
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /projectfoldername/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^page1/(.+?)/?$ /projectfoldername/page1.php?key=$1 [L,QSA]
page1.php code will be
<?php
echo $_REQUEST['key'];
?>
then call
http://localhost/projectfoldername/page1/1947
output will be :1947

Removing File URL with .htaccess

I am writing a program and run it locally with xampp. the full path to the program is http://192.168.101.103:7777/WeltesMaft/index.php
I am writing a .htaccess in C:\xampp\htdocs\WeltesMaft\
containing this
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/([^/]+)$
RewriteRule .* http://192.168.101.103:7777/WeltesMaft/%1 [L]
but somehow my htaccess doesnt work. it still showing like this
http://192.168.101.103:7777/WeltesMart/_resources/main.php
which is in index.php i am including main.php. So when user enters index.php, it will redirect to main.php in an instant.
I want to hide it so that the url looks like this,
http://192.168.101.103:7777/WeltesMart/
Please help me what am i doing wrong here...
You can use this code also.....
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ _resources/main.php/$1 [L,QSA]
</IfModule>
Change RewriteBase to your directory name and change the htaccess rule as following and try again:
RewriteEngine On
RewriteBase /WeltesMaft
RewriteCond %{REQUEST_URI} ^/([^/]+)$
RewriteRule / index.php [L]

Htaccess code redirects to XAMPP index page

I am trying to write htaccess codes which redirect all URLs apart from directly linked files (e.g images & css files) to my index.php file for processing
http://localhost/testsite/login
redirects to
http://localhost/testsite/index.php?cmd=login
But the htaccess code instead redirects me to the XAMPP homepage. This is my htaccess code
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?cmd=$1 [QSA,NC,L]
What am I doing wrong?
Remove / from target and use proper RewriteBase:
DirectoryIndex index.php
RewriteEngine on
RewriteBase /testsite/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?cmd=$1 [QSA,L]
/index.php will route it to site root index.php instead of index.php in current directory.

php friendy url using htaccess

I have the following code on my htaccess:
RewriteEngine On
RewriteRule ^course-details/([a-zA-Z0-9]+)/$ course-details.php?id=$1
I think this gave me a URL like this: /cp/course-details/5 where 5 is the id of the course.
But when I go to this address I get 404 not found. Also, our current url is
/cp/course-details.php?course-details.php?name=bla-bla-bla&category_id=1
and we need a friendly url like this
cp/category-name/course-name/
Thanks in advance for you help.
You can try this in your htaccess file if the php file is in the cp dir. Since it appears your are developing in a subfolder(peppers) of your dev box you can try this.
RewriteEngine On
RewriteBase /peppers/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^cp/course-details/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
If this is for production then you can use this in the .htaccess file in the root.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^cp/course-details/([^/]+)/?$ /cp/course-details.php?name=$1 [NC,L]
RewriteRule ^course-details/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/.*$ course-details.php?id=$1&category_id=$2
With that, you can use URL like course-details/1/5/category-name/course-name
Because URL allow: course-details/category_id/id/what-ever-you-want

Loading a single file for all pages

I am running a Apache webserver, my goal is to have a loader (In PHP) that gets loaded from all URLs. For example if you head to website.com/test/, website.com/page.php or just website.com/ it will always load website.com/index.php
How can i achieve this?
You can create a .htaccess file that will rewrite the URL for anything this is not a file or directory on your server and redirect it to the index.php file. Additionally you can have the original URL attached as the query string so you can work with it in your script if need be.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
</IfModule>
Create a .htaccess file with the following lines and put it in the root directory of your website:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
If a .htaccess file already exists, you can try appending those lines if there's no conflicting rules.

Categories