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

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

Related

how to change default page index.php to url

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]

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]

how to add index.php in the URL through htaccess

Actually I need to add index.php in my application URL through htaccess file.
My URL is like this.
http://localhost:8080/myapp/xyz/abs.html
I need to change this into.
http://localhost:8080/myapp/index.php/xyz/abs.html
Can anyone tell me what i need to be write in htaccess file.
Any Help will be appreciating.
Thanks.
Have this rule in /myapp/.htaccess:
RewriteEngine On
RewriteBase /myapp/
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+) index.php/$1 [L]
Presumably an internal rewrite is required, not an external redirect? In which case, try something like the following, using mod_rewrite in your root .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_URI} !/index\.php/
RewriteRule ^myapp/(.*) /myapp/index.php/$1 [L]
The RewriteCond directive is required to prevent a rewrite loop. (Only rewrite if it doesn't already contain "/index.php/".)
Try this in your htaccess
RewriteEngine on
RewriteCond %{THE_REQUEST} /myapp/xyz/([^.]+)\.html [NC]
RewriteRule ^ /myapp/index.php/xyz/%1.html [R,L,NC]

remove 3 directories in url via htaccess file

I want to convert the URL http://localhost/project1/mvc/public/content/1 to the URL http://localhost/content/1.
I have my .htaccess file placed in the public folder that removes the index.php in the URL.
Options -MultiViews
RewriteEngine On
RewriteBase /project1/mvc/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Here's my directory structure:
Project 1
---mvc
-----app
-----public
I need help in the creating .htaccess file for this. What is the syntax for modifying the URL and which folder/s should I put the .htaccess file/s?
Thanks
You can use this code in your DOCUMENT_ROOT/.htaccess file (above a directory level of mvc):
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?!/project1/mvc/public/).*) project1/mvc/public/$1 [L,NC]

.htaccess all request to other file

Currently I have the following .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/index.php/$1 [L]
</IfModule>
Which works allmost perfect.
It rewerites urls like http://domain.com/something/ to the public/index.php file, like a charm, except when it is a file, just like it should.
However http://domain.com (without any path appended) (there is no index.php in the root, so it gives a 404 at the moment) is not being rewrited, how can I change this .htaccess so it rewrites this url too?
The index file is in public/index.php I want it to load that file through the use of .htaccess
Thanks
I believe to rewrite the root, you can simply do something along the lines of:
RewriteRule ^$ location/of/root/file [L]
You could try:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/index.php
RewriteBase should prepend the rule pattern with a leading slash, forcing it to match the root path.
Untested!
What you have there is inspired by WordPress?? It's a bad idea as it tell Apache to always check if the path is a file or a directory before redirecting.
I have something like this
RewriteEngine On
RewriteCond %{REQUEST_URI} !^.*/(css|images|javascript)(.*) [NC]
RewriteCond %{REQUEST_URI} !\.(swf|ico|php|xml)$ [NC]
RewriteCond %{REQUEST_URI} !robots.txt
RewriteRule (.*) index.php?page=$1&%{QUERY_STRING} [PT]
The first condition restricts this redirect from working in specific folders.
The seconds does it for specific extensions.
You can guess what the third does :)

Categories