.HTACCESS - Get the parameter and rewrite - php

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

Related

how to add pagination in htaccess rewrite rule

I'm looking to add pagination with htaccess.
Visible URL:
example.com/test/page2
To:
example.com/test/pagination.php?page=2
Thanks in advance.
Basically you just need to capture the page number and then recycle it into the correctly formatted URL.
RewriteRule ^test/(\d+)/*$ /test/pagination.php?page=$1 [L]
RewriteRule : Type of action
^test/(\d+)/*$ : Regex to run against URL
/test/pagination.php?page=$1 : Replacement URL
[L] : Flags; L == Last
Example:
example.com/test/5 >>> example.com/pagination?page=5

Read parameter using rewriting engine

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

URL rewriting in PHP using htaccess file

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

How to make HTACCESS URL with getting other variabel PHP

I get problem while implement .htaccess file,
for general htaccess like : sitename.com/id/other_var its working very well to getting $_GET Request,
RewriteRule ^sitename.com/id/other_var$ index.php?id=$1&othervar=$2 [L]
my problem is, I need to implement like : sitename.com/id/other?a=x&b=y ,
how it work on htaccess ?
thank you for helping!
Mod Rewrite can use simple regex statements to achieve this..
RewriteRule ^sitename.com/([0-9]+)/(.*)$ index.php?id=$1&othervar=$2 [L]
The above would pass an integer value for id and allow anything passed for othervar

Htaccess Rewriting part of url

I have this adress :
localhost/wattathome/view?slug=multiples-services
And I would like to rewrite it like that :
localhost/wattathome/view/multiples-services
or even better :
localhost/wattathome/multiples-services
But everything I try with Rewriterule ends up with a 404 error.
Please help me D:
Thanks in advance.
If i understnad correctly your code
RewriteRule ^view/([A-Za-z0-9-]+)/?$ view.php?slug=$1 [NC,L]
will get view?slug=multiples-services and rewrite it to
localhost/wattathome/view/multiples-services/ (note the end slash)
Try removing the ending slash and see what will happen
EDIT 1
Ok les try this one (remember, view.php must be in root folder):
RewriteRule ^view/([^/]+)$ view.php?slug=$1 [NC,L]
Make sure that you have all your redirection rules above any rewrite rule.
So, your htaccess should look like:
- options
- redirections
- rewritting

Categories