I am trying to display the details of specific project based on the parameter i.e id passed on the url. But i don't want the page and the varialble be displayed on the url and wish to use only the parameter to do further funtioning by using $_GET['id']. My code somewhat works this way....
Get Detail
address bar is :: localhost/project/details.php?id=1456
can i get something like :: localhost/project/1456
thank you.
Create a .htaccess file in your project folder and copy these lines into .htaccess
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/project/([0-9]+)$
RewriteRule ^(.*)$ /project/your_file_to_run.php?id=$1 [L]
In your php file your_file_to_run.php you can use $_GET['id'] to get the value of id
Put this in your project directory
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([\d]+)$ details.php?id=$1
I assume You are using Apache. So enable mod-rewrite and put .htaccess file into your web root directory.
To configure frendly linka You need smth like:
RewriteEngine On
RewriteRule ^/?(.*)$ details.php?id=$1 [NC,L]
--EMPTY LINE OR FILE WILL FAIL--
This file should reside in project dir
Empty line is important!
Related
I have a php file which is home.php
my url on localhost is
http://localhost:8888/photo/home.php
I want to remove .php from the url
so i create .htaccess file
RewriteEngine On
RewriteRule ^home?$ home.php
but i keep getting this error
The requested URL /photo/home was not found on this server.
First of all, ensure your .htaccess file is in the base directory of your project. Next, follow these htaccess rules to set up your redirect.
The .htaccess solution you might be looking for is:
RewriteEngine On
#Neither a file nor a directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^photo/home$ photo/home.php [QSA,L]
Try it like this, in your photo directory.
RewriteEngine On
# neither a file nor a directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^home$ home.php [QSA,L]
I got this problem when I put the .htaccess code in the root .htaccess. It works when I create a new .htaccess in the subdomain folder on the same level with public_html folder and fill it with the RewriteRule needed
I need a suggestion using .htaccess (I presume) or any other solution for the following situation:
On the server, for example I have a folder www.mypage.com/accommodation/ which contains index.php script.
What I would like to do is that when the called URL is something like www.mypage.com/accommodation/apartment-mike (note no / in the end or extension), that the string "apartment-mike" ($_SERVER['request_uri']) is passed to the index.php script in the accommodation folder instead of trying to directory walk apartment-mike directory.
What would be the best way to do this?
First you must rewrite the call to index.php. This is a classic and can be found anywhere
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php [L]
The next step is accessing the URI itself, which you already figured yourself by using $_SERVER['REQUEST_URI'].
You can add the file apartment-mike.php, contains a ridirection to index.php, to the accomodation folder then add the following lines to the .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
to remove the extension from appearing in the uri
don't forget to add
header("location:index.php");
to the apatement-mike.php if you want it to pass users to the index
Currently, I'm trying to set up updates for passes that are added to the Wallet app on iOS.
One thing that is interesting is that having the url https://example.com/index.php/var1/var2 still works and index.php is still run. Is there a reason why this url format works?
.htaccess/mod_rewrite is the reason why it's working.
For example:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
Having this rules inside a file named .htaccess in the root folder of your website, will make the path /var1/var2 available inside $_GET['path']
I have a problem with Htacces file , the thing is I am trying to do a Profile URL
ex : www.mysite.com/profilename --> this link will take me to the user profile and its working because of
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?u=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?u=$1
no the thing is whenever I try to access any other directory for example www.mysite.com/login it changes the url to www.mysite.com/login/u?=login
Depending on if login is an actual file or directory rather than another script needing another htaccess rule.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
This checks first to see if the directory or file exists before executing your RewriteRule directive.
I have a directory in my site with a bunch of temporary PHP generated PDF files.
mysite.com/crm/pdfs/
I have an .htaccess file located in the pdfs/ directory with the intention of redirecting all requests within that folder to the index.php page within that folder and include the original request in the query string. For example,
When a browser is pointed to:
mysite.com/crm/pdfs/somepdf.pdf
it should be redirected to
mysite.com/crm/pdfs/index.php?p=somepdf.pdf
Here's my current try:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]
The problem with this is, when the user requests:
mysite.com/crm/pdfs/somepdf.pdf
They are instead redirected to
mysite.com/index.php
and the original request is not appended.
How can I achieve the desired result in my .htaccess that is located in the /pdfs directory?
Use this rule in your /pdfs/.htaccess:
RewriteEngine On
RewriteBase /crm/pdfs/
RewriteRule ^(.+?\.pdf)$ index.php?p=$1 [L,QSA,NC]