I have folder strcture like below
-folder
--text
---index.php
and I have a URL like below
https://example.com/folder/test/index.php?slug=slugname
I added below code in the htaccess to rewrite the URL.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?slug=$1 [QSA,L]
So now my URL is
https://example.com/folder/test/slugname
I have to get the slugname on my php page and I tried echo $_REQUEST['slug']; and echo $_GET['slug']; but I am getting
slugname.php
I want only my slugname.
Please keep following .htaccess Rules file besides your folder named folder and try following rules. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine On
RewriteBase /folder/test/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/?$ index.php?slug=$1 [QSA,L]
Related
My site has URL like this
www.abc.com/search?service=computer
I want
www.abc.com/service/computer
Tried htaccess file is:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ([^/\.]+)/([^/\.]+)/?$ search.php?type=$1&service=$2
Thanks, Please help me to write this URL in SEO URL
Please keep your htaccess file inside root folder/directory and try following rules. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/?$ search?$1=$2 [L]
I am trying to create a rewrite rule in my Apache .htaccess file and the goal is:
http://domain/folder/(any search string) to redirect to http://domain/folder/index.php?option=$1
example:
http://domain/folder/covid to redirect to http://domain/folder/index.php?option=covid
I got this setup in htacess in http://domain/folder, but somehow it's not working:
RewriteEngine On
RewriteRule ^([^/folder]+)/([^/]+)$ http://domain/folder/index.php?option=$1 [L]
The website is hosted on http://domain/folder
Can someone help me on this?
You may try this .htaccess inside folder/:
RewriteEngine On
RewriteRule ^index\.html?$ index.php [L,NC]
RewriteRule ^index\.php$ - [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .+ index.php?option=$0 [L,QSA]
You could have your htaccess file like as follows. Please keep your htaccess file along side with your folder(named folder) and NOT inside folder.
Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php?option=$1 [L]
OR in case your htaccess is present inside folder folder then try following.
RewriteEngine ON
RewriteBase /folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php?option=$1 [L]
I have a custom php file at the following url
http://example.com/index.php?route=product/overview&pid=85
and i want only this URL to rewrite like as below
http://example.com/overview/85
No other URLs shall be affected in the website. Is that possible using htaccess to rewrite only one specific URL.
I tried like below
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/$ /product/overview&pid=?$1 [L]
But it is not working
You can use this :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?route=product/$1&pid=$2 [L]
I am trying to use mod-rewrite in .htaccess for implementing clean/pretty URLs.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ details.php?id=$1 [L,QSA]
RewriteEngine On turns the engine on.
RewriteCond %{REQUEST_FILENAME} !-f does not rewrite anything if the
request filename exists, and is a file.
RewriteCond %{REQUEST_FILENAME} !-d does not rewrite anything if the
request filename exists, and is a directory.
RewriteRule ^([^/]+)/?$ details.php?id=$1 [L,QSA] This is the actual
rewrite rule. It takes anything after the domain name (anything
other than forward slashes), and rewrites it to details.php, passing
it as the id parameter.
RewriteRule ^([^/]+)/?$ details.php?id=$1 [L,QSA] is working when request for http://www.domain.com/texas
This is well and good. What I need is that my request URL looks like this:
http://www.domain.com/location/texas
and details.php has the below code
<?php
$id = $_GET["id"];
echo "new id is ".$id;
?>
Problem: I couldn't write a valid .htaccess RewriteRule to identify this request http://www.domain.com/location/texas.
Please help.
What all I tried?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^location/?$ details.php?id=$1 [L,QSA] - not working
RewriteRule ^location/[a-z][-a-z0-9]*?$ details.php?id=$1 [L,QSA] - working, but id is displayed blank.
You can just tweak your existing rule by making starting location/ optional:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:location/)?([^/]+)/?$ details.php?id=$1 [NC,L,QSA]
I am using Slim php framework, having no .htaccess file in root folder I can call the pages
like /index.php/pagename
but if I upload the following .htaccess file in the root folder I always get 403 Forbidden error like You don't have permission to access /hello on this server.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
Try changing your rule to this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [L]
Then you can use a URI /hello which will be rewritten to /index.php/hello.
Please review the Route URL Rewriting
section of the Slim documentation. The .htaccess provided there is different than those posted here.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]