I have this type of url :
domain.com/articles/title
And i want to rewrite this url in :
domaic.com/articles.php?id=title
I use this rewrite condition:
RewriteEngine On
RewriteRule ^articles/(.*)$ articles.php?id=$1 [QSA,L]
I can show the page articles.php but i try to read value of id's variable with $_GET['id'] but is empty.
Thank in advance for your reply
Related
I have a url
website.com/v2/main-service.php?service=foo-bar
and I want to mask it so that the url will become
website.com/v2/foo-bar.html
I have this .htaccess code
RewriteEngine on
RewriteRule ^foo-bar.html$ main-service.php?service=foo-bar
but it's not working. I will appreciate the help. Thank you.
your rule is correct if you remove the "^" before foo-bar.html,
You can add variable and it give something like this :
For this url :
http://website.com/v2/foo-bar.html
The rule :
RewriteRule (v[0-9])+/([a-z0-9-]+).html$ /$1/main-service.php?service=$2
result for php : http://website.com/v2/main-service.php?service=foo-bar
Try this here :
http://htaccess.mwl.be?share=341609bf-eda9-5a5e-92f5-a2cc3f01f921
EDIT : I change rule without index.php
I have page redirect URL like below with more than one parameters.
http://example.com/search.php?layout=details&Keyword=mobile&view=product&CategoryId=1026&product_id=93477
From that URL i'm taking all parameter values to take a data from database.
So when i load this page i need to show URL most user friendly like below. In that URL should contain only the value of product_id which is i'm using my redirect URL
http://example.com/93477.htm
I have tried to rewrite this URL like below. But in that i couldn't use the parameters "categoryId" and "keyword"
rewrite ^/([a-zA-Z0-9/-]+).htm /search.php?layout=details&view=product&Keyword=$3&CategoryId=$2&product_id=$1 last;
Please anyone help me to done it successfully..
Regards,
VIGNESH KUMAR K
Try this mate ,
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/search\.php\?layout=details&Keyword=([^&]*)&view=product&CategoryId=([^&]*)&product_id=([^&]*) [NC]
RewriteRule ^ /%2/%3/%1? [L,NE,R=302]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /search.php?layout=details&Keyword=$2&view=product&CategoryId=$3&product_id=$1 [L,QSA]
The original URL:
http://example.com/search.php?layout=details&Keyword=mobile&view=product&CategoryId=1026&product_id=93477
The rewritten URL:
http://example.com/93477.htm
Update 1 :
[QSA] has been added in the above code now so that to append the query string in order to retrive
dynamic parameters using PHP $_GET
http://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsa
Update 2:
Edited the .htaccess code to make Keyword and CategoryId Dynamic
My URL is
localhost/Interview/php/SEO_URL/01-example/create_user.php
want to change this into
http://localhost/Interview/php/SEO_URL/01-example/CreateUser
want to create a base url like this
localhost/Interview/php/SEO_URL/01-example/
How ?
You can use the following rule in /root/.htaccess :
RewriteEngine on
RewriteRule ^interview/php/SEO_URI/01-example/create_user/?$ /Interview/php/SEO_URL/01-example/create_user.php [NC,L]
This will internally redirect the requestd url :
interview/php/SEO_URI/01-example/create_user
to
/Interview/php/SEO_URL/01-example/create_user.php
RewriteEngine On
RewriteRule ^about/([^/.]+)/?$ about.php?id=$1 [L,QSA]
I have a page use htaccess rewrite rule for url
/about/33
the page require $_GET['id'] to fetch db
however i have trouble to detect GET variable isset
if(isset($_GET['id'])){fetch data...}else{header("location:...");}
if user only enter /about/ without $GET['id'] the page will not found instead run header("location");
is anyway to solve this?
try this:
RewriteRule ^about/([^/.]*)/?$ about.php?id=$1 [L,QSA]
Put * instead of +
i wrote this Rewrite Rule :
RewriteRule ^(products)/(page[0-9]+)?/?$ index.php?action=$1&page=$2 [L]
in following url this will happen :
rewrited url : http://www.silvergroup.ir/products/page2
what actually is : http://www.silvergroup.ir/index.php?action=products&page=page2
but i need the number of page only and whole of page variable is optional, this means following url is allowed :
http://www.silvergroup.ir/products
thank you
Use this rule instead:
RewriteRule ^(products)(?:/page([0-9]+))?/?$ index.php?action=$1&page=$2 [L,NC,QSA]
This will forward
/products to /index.php?action=$1&page=
/products/ to /index.php?action=$1&page=
/products/page2 to /index.php?action=$1&page=2