My URL is like
http://172.16.3.97:82/shop/t-shirts/full-zip-sweatshirt?options=367:731,368:737,369:741&custom_inscription=test
and I wrote rewrite rule like
RewriteRule ^shop/t-shirts/([a-zA-Z0-9\-#]+)\?*$ shop/product?path=35&product_id=$1&test=$2
I got only full-zip-sweatshirt in $_GET but I am not able to get other parameters.
How should I write Rule in .htaccess ?
Try to change your rewrite rule for this :
RewriteRule ^shop/t-shirts/([a-zA-Z0-9-#]+)\?*$ shop/product?path=35&product_id=$1&test=$2 **[L,QSA]**
The flag "QSA" add the original query string to your query
Or maybe this one should also help :
RewriteRule ^shop/t-shirts/([a-zA-Z0-9-#]+)\?*$ shop/product?path=35&product_id=$1&test=$2&%{QUERY_STRING}
Related
Please help me in writing correct .htaccess code to get the wanted result.
I have the following pages:
www.mydomain.com/?exam=/hp-certification/
www.mydomain.com/?exam=/cisco-certification/
www.mydomain.com/?exam=/oracle-exam-prep/
www.mydomain.com/?exam=/faq/
www.mydomain.com/?exam=/support/
And there are many more pages but you can notice that the fixed part is: www.mydomain.com/?exam=
Instead of using query string links, I want the following links to work as above pages:
www.mydomain.com/hp-certification/
www.mydomain.com/cisco-certification/
www.mydomain.com/oracle-exam-prep/
www.mydomain.com/faq/
www.mydomain.com/support/
and so on.
your link should be like this www.mydomain.com/?exam=hp-certification/ and the rewrite rule would like this in .htaccess file.
RewriteEngine On
RewriteRule ^([^/.]+)$ /?exam=$1 [L]
You can do that by using the following rules in your .htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} exam=(.+) [NC]
RewriteRule ^(.*)$ http://www.example.com/%1? [R=301,NC,L]
So what does the above do?
First, it will take the query exam= as a condition, if this condition is met then it will grab any version of the variable using (.+).
It will then rewrite the URL using 301 redirection to show http://www.example.com/anything/. The use of %1 is to grab the variable from exam= and then we use ? to stop the original query string from appearing on the end of the newly rewritten URL.
Make sure you clear your cache before testing this.
I Want to rewrite the url using .htaccess
Plz Read the code, and you well Get to know What I mean
My URL :
article.php?id=1&title=example
Using this in .htaccess
RewriteRule ^article/([0-9]+)/([0-9a-zA-Z_-]+)$
article.php?id=$1&title=$2 [NC,L]
I get
article/1/example
What i need is
article/example
So something like this:
RewriteRule ^article/([0-9a-zA-Z_-]+)$ article.php?title=$1 [NC,L]
I was using mod rewrite to create clean urls. I have urls like this :
http://www.sitename.com/viewcategory.php?id=262
I have rewritten successfully my url like this :
http://www.sitename.com/262
With the following mod_rewrite rule
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ viewcategory.php?id=$1
RewriteRule ^([a-zA-Z0-9]+)/$ viewcategory.php?id=$1
What i want is to display the category name somthing like this:
http://www.sitename.com/categoryname
Please suggest me if there is a mistake in my rewrite rule or I need to do something else.
Thanks and regards.
I have a code igniter site that needs to accept incoming links in the format:
http://domain.tld/somename.html?id=IDREF
I need to create a rule for mod_rewrite that rewrites this URL to:
http://domain.tld/index.php/controller/somename/IDREF
I am having trouble writing the rule for the .htaccess file.
I thought this should work:
RewriteCond ${QUERY_STRING} ^(.*\.html\?id=.*)$
RewriteRule ^([^/]*)\.html\?id=(.*) /index.php/controller/$1/$2 [L]
But as I am a bit of a novice at mod_rewrite I can't get it to work.
Just to clarify I want the user to link to this ugly url and get sent to specific controller.
Try this:
RewriteCond ${QUERY_STRING} ^id=
RewriteRule ^(.*)\.html?id=(.*) index.php/controller/$1/$2 [L]
You might need to add a question mark after the second $2 if you get the original query string appended somehow after the rewrite
I have rewrited my url's with htaccess and now I want to redirect the old url's to the new ones, but I can't figure it out how to do it after all.
This is my redirect rule used:
RewriteRule ^page/([^/]*)/$ /page.php?name=$1 [L]
The old url's look like this: page.php?name=page-name
The new url's look like this: /page/page-name/
That's a bit complex when you want redirect an url with GET parameters.
Here's a trick to do it :
RewriteRule ^page\.php$ %{QUERY_STRING} [C]
RewriteRule name=(.*) /page/$1/? [R=301,L]
Explainations :
First, you redirect page.php?name=page-name to ?name=page-name
Then, you ask using the following rule for this result (with [C] tag)
Third, you redirect page-name, picked with (.*) to page/page-name/
Last trick, if you don't put the last ?, your query string will be appended to your result and you'll have this kind of url : page/page-name/?name=page-name. Using an useless ? erase the old GET parameters.
Found some informations here :
Apache mod_rewrite doc
How to strip a query string