I tried to re-write on my own but unable to do so, basically, I want to re-write php-based URL with .htaccess but also need to skip few parameters of php URL for example;
Original URL:
http://example.com/details.php?id=62?title=billions-s01e09-webrip-x264-fumettv
Required Format:
http://example.com/billions-s01e09-webrip-x264-fumettv-id62.html
Format Sequence:
MySiteURL/Title-of-Post-PostID.html
Looking for kind response, please guide me how can i make this possible through .htaccess.
waiting for kind response...
Good day
As you already know that you have to change the .htaccess file in your server. You can use regx to achieve your required url. Using the following code can help you.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9-]+)-id([0-9]+).html?$ details.php?id=$2&title=$1 [QSA,L]
worked fine for me. Hope will work for you too.
To rewrite
http://example.com/foobar-id123.html
to
http://example.com/details.php?id=123?title=foobar
You can use the following rule :
RewriteEngine on
RewriteRule ^([^-]+)-id([0-9]+)\.html$ /details.php?id=$2?title=$1 [NC,L]
Related
.htaccess newbie here.
I have a URL like this:
example.com/lesson-plans/earth-sciences/show_lesson_plan.php?title=Some_Title&id=6
that I need to be rewritten like this:
example.com/lesson-plans/earth-sciences/some-title-6
I am using the following .htaccess URL rewrite:
RewriteEngine On
RewriteRule ^lesson-plans/earth-sciences/([^/]*)/([^/]*)$ /lesson-plans/earth-sciences/show_lesson_plan.php?title=$1&id=$2&cat=3 [L]
However, when I hover over/click on links of the original format (example.com/lesson-plans/earth-sciences/show_lesson_plan.php?title=Some_Title&id=6), they are not being rewritten. I've tried a few different rewrite rules, but nothing works.
How can I make this rewrite work? As far as I know, .htaccess is working on my server and rewrites are permitted.
You were close
RewriteEngine on
RewriteCond %{QUERY_STRING} title=([^&]+)&id=([^&]+)
RewriteRule ^lesson-plans/earth-sciences/show_lesson_plan.php$ /lesson-plans/earth-sciences/%1-%2 [QSA,L,R]
Randomly while lying in bed last night.
You have the rewrite rule back to front. you have to add the rule for the rewritten url to turn it back into an ugly one
see: http://martinmelin.se/rewrite-rule-tester/
RewriteEngine On
RewriteRule ^lesson-plans/earth-sciences/(.*)-(.+)$ /lesson-plans/earth-sciences/show_lesson_plan.php?title=$1&id=$2&cat=3 [L]
so
lesson-plans/earth-sciences/some-title-6
becomes
/lesson-plans/earth-sciences/show_lesson_plan.php?title=some-title&id=6&cat=3
I ended up using the following code and am posting it as an answer in the event someone else finds this useful:
RewriteEngine on
RewriteRule ^([^/.]+)/([^/.]+)$
show_lesson_plan.php?title=$1&id=$2
This will take a url (like this: http://example.com/lesson-plans/earth-sciences/a-cloud-in-a-bottle-i/8923) and run it through this: http://example.com/lesson-plans/show_lesson_plan.php?title=$1&id=$2
Note that I changed the original URL slightly, opting to break the id out of the title string.
I am using the following code in .htaccess direct editor in ipage server for changing my website's page url from
for example:
http://foodinger.in/viewRestaurant.php?raipur=Barbecue-Country&id=3006
to
http://foodinger.in/viewRestaurant/raipur/Barbecue-Country
but it is not working
RewriteEngine on
RewriteRule viewRestaurant/raipur/(.*)/ viewRestaurant.php?raipur=$1&id=$2
RewriteRule viewRestaurant/raipur/(.*) viewRestaurant.php?raipur=$1&id=$2
Am i doing anything wrong, Please anyone suggest me the right way if i am wrong ?
Thanks in advance
You specify only one group for substitution (.*) that will replace $1 in target url.
Try:
RewriteEngine on
RewriteRule "^/viewRestaurant/raipur/(.*)/(.*)/?" "/viewRestaurant.php?raipur=$1&id=$2"
And query with Id: http://foodinger.in/viewRestaurant/raipur/Barbecue-Country/3006
Good days guys, I need your help with this url rewrite.
The are two rewrites I want to do.
1) I want to take out .php from the url even though my files is saved as .php
2) I want to rewrite the url below
www.example/account/product.php?Sef=shoes&pid=3
To something like this
www.example/account/product.php?Sef=shoes/pid/3
If you can help me. It will be lovely. Thanks
For your second problem you don't need htaccess for that just parse $_GET['Sef'] on your server side.
As per php extension try this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
i can change my url in simple form.
how can i use rewrite rule in htaccess
my url is http://test.com/wishdetails?wishid=czoyOiIzNiI7&title=my_weekend_story
i want this http://test.com/wishdetails/my_weekend_story
so please help me. how can i change
please do reply fast.
Thanks....................
You could achieve that using this code:
RewriteEngine On
RewriteRule ^wishdetails/my_weekend_story$ wishdetails?wishid=czoyOiIzNiI7&title=my_weekend_story
Or if my_weekend_story is variable, you could use this code:
RewriteEngine On
RewriteRule ^wishdetails/(\w+)$ wishdetails?wishid=czoyOiIzNiI7&title=$1
Please do note that you will need to have enabled mod_rewrite if you are using Apache.
RewriteEngine On
RewriteRule ^wishdetails/([^/]*)$ /wishdetails?wishid=czoyOiIzNiI7&title=$1 [L]
I'm trying to convert a simple url (below) in to a blog-style url, but not quite sure how to do it, all of my other rules are working fine, but I can't seem to figure this one out.
URL I want to convert: http://www.website.com/myblog.php?id=1&title=My+blog+title
URL I want it to create: http://www.website.com/1/my-blog-title
What should the rule be?
Any assistance appreciated :)
Try this
RewriteEngine on
RewriteBase /
RewriteRule ([0-9]+)/([^.]+) myblog.php?id=$1&title=$2
Try this in your .htaccess file:
RewriteEngine on
RewriteRule ^(\d+)/([^/]+)$ myblog.php?id=$1&title=$2
But here the hyphens are not replaced by plus signs.
in your .htaccess file,
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /myblog.php?id=$1 [L]
You don't (well shouldn't) need to pass the blog title to the blog file, only the ID. Hope this works