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]
Related
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 am on apache 2 and I would know if my htacces is correct
my url are for example :
localhost/test/boutique/index.php
localhost/test/boutique/index.php/language,en
localhost/test/boutique/index.php/Products/Description/products_id,1
localhost/test/boutique/index.php/Products/Description/products_id,2/language,fr
What is the best approach for a good url like above
In suppose index.php must deseapear to hav someting like that
localhost/test/boutique/Products/Description/products_id,1
I try this but it does'nt work
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://localhost/test/boutique/index.php/$1 [PT,L]
Assuming /test/boutique/ is a real directory, you can use these rules inside /test/boutique/.htaccess:
RewriteEngine On
RewriteBase /test/boutique/
# remove index.php if entered directly by clients
RewriteCond %{THE_REQUEST} /index\.php/(\S*)\s [NC]
RewriteRule ^ %1 [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!index\.php$).* index.php/$0 [L,NC]
I want to redirect from http://www.domain.com/customer1 to /app/index.php?c=customer1 and http://www.domain.com/customer2 to /app/index.php?c=customer2
I tried the below rule but not works well...
RewriteRule ^customer1(.*)$ /app/index.php?c=customer1
I am assuming you are talking about rewriting,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)$ /app/index.php?c=$1 [QSA,L]
This will internally rewrite your urls if not rewriting then try it like this,
RewriteEngine on
RerwiteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)$ /app/index.php?c=$1 [R=301,QSA,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 trying to create mod_rewrite rules that rewrite based on the first level directory name plus a failover to rewrite to a standard file in case none of the directory names are matched.
Example:
I have units.php, models.php and other.php. The other.php file should handle all non-assigned requests.
http://www.mydomain.com/units/4435
Should redirect to /units.php?id=4435
http://www.mydomain.com/models/594
Should redirect to /models.php?id=594
http://www.mydomain.com/anything
Should redirect to /other.php?id=anything
http://www.mydomain.com/anything/893
Should redirect to /other.php?id=anything/893
Let me know if this makes sense. I am unsure of how to structure the rules and conditions to achieve what I want.
This is what I have tried to sfar. It works for URLs starting with 'units' or 'models' but I get a 500 Error if I try any other URL:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(units)/(.+)$ /units.php?id=$2 [L,NC]
RewriteRule ^(models)/(.+)$ /models.php?id=$2 [L,NC]
RewriteRule ^(.+)$ /other.php?id=$2 [L,NC]
I would suggest this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(units|models)/([0-9]+)/?$ /$1.php?id=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(units|models)/[0-9]+/?$
RewriteRule ^/[^/]+/([0-9]+)/?$ /other.php?id=$1 [L,QSA]