I have URLs that look like this:
page.php?id=1&lan=en
I want to change it to page-1.html?lan=en via htaccess.
Please note that I have to get the value of both parameters id and lan too.
Thanks in advance.
You can use codes below. I didn't try it, but it should work
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^page-(\d*).html$ page.php?id=$1 [L,QSA]
Related
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]
I am not very good with .htaccess, and I am trying to rewrite URLs with variables. I tried to follow other topics advice but couldn't get it to work.
I go some urls that are like this:
/en/22-products/ (the url continue but I don't want to change the rest)
I would like to change them like this: /en/catalog/22-products/
Now I got this in my .htaccess:
RewriteRule ^en/([0-9]+)-products/?$ /en/catalog/$1-products/ [R,L]
But it won't work. Where am I wrong?
You were not far. We also need to pick up the trailing part of the url. Do it like this:
RewriteEngine On
RewriteRule ^en/([0-9]+-products)(.*) /en/catalog/$1$2 [L,R]
I want to change dynamic URL's to URL's more acceptable by search engines.
For example change this :
http://myurl.com.au/page.php?id=100&name=myname
to
http://myurl.com.au/100/myname.php
or .html at the end it does not matter.
I am using Apache 2.2. I am not using .htaccess rather I put my code in /etc/httpd/conf/vhosts/myfile
but it does not work, the URL does not change at all.
Options Indexes Includes +FollowSymLinks
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)\.php$ /page.php?id=$1&name=$2 [L]
What am I doing wrong?
Either your have the wrong description in your question or your rule is backwards. Maybe this could work:
Options Indexes Includes +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} id=(.*)&name=(.*)$
RewriteRule ^/page\.php /%1/%2.php [L]
After doing some further testing it turns out that I do have the right code. I just don't have my head screwed on and was not thinking. Expecting that the mod_rewrite would magically change the URL to symbolic links when it is actually doing the reverse of that. It is all working for me now.
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