I am trying to rewrite this url and it just doesn't seem to be working and I am unclear what is going wrong
I want this URL:
www.mysite.com/dvd-123/Studio/studio_name.php?thumbs=yes&order=price
To actually send to:
www.mysite/cat/list_products.php?studio=123&store=dvd&thumbs=yes&order=price
Here is what I have that is sorta working:
RewriteRule ^dvd-([0-9]+)/Studio/(.*)\.php?(.*)$ cat/list_products.php?studio=$1&store=dvd&$3 [L]
The results I am receiving are the same as if i want to:
www.mysite/cat/list_products.php?studio=123&store=dvd
ignoring the:
&thumbs=yes$order=price
Thank you in advance for your help!
From Apache documentation:
The Pattern will not be matched against the query string... To combine a new query string with an old one, use the [QSA] flag.
I haven't tested this, but hopefully it should point you in the right direction.
RewriteRule ^dvd-([0-9]+)/Studio/(.*)\.php$ cat/user_list_products.php?Manname=$1&store=dvd [L,QSA]
You need to escape the slashes.
RewriteRule ^dvd-([0-9]+)\/Studio\/(.*)\.php?(.*)$ cat/user_list_products.php?Manname=$1&store=dvd&supersale=$3 [L]
Related
My aim is this URL:
component/users/?view=registration
To:
registration.html
the .htaccess is in the folder mysite of the website.
i tried this:
RewriteBase /mysite
RewriteRule ^component/users/?view=registration$ registration.html$ [R=301,L]
But i doesnt work...
When i try this:
RewriteRule ^component/users/_view=registration$ registration.html$ [R=301,L]
it works very well.
So how can i fix this problem with the question mark. I already read thats it is not a part of the URL (its appended). I have read that i have to use something like querystring, but i didn't really understand the syntax.
Maybe someone could write the solution of this problem? Would be awesome =)
You need to use %{QUERY_STRING} to capture the query string data:
RewriteCond %{QUERY_STRING} ^view=(.*)$
RewriteRule ^component/users/?$ %1.html? [R=301,L]
The above rule/condition will take the value of the query string view and use it to form your redirect if the path component/users matches.
RewriteRule ^component/users/\?view=registration$ registration.html$ [R=301,L]
You need a \ because ? is part of a regular expression. To Use it as a string u need to escape it with a \
Linktip: http://ole.michelsen.dk/tools/regex.html
Hoping someone can help me with this issue...
I have a RewriteRule set up in my htaccess file that looks like this
RewriteRule ^/?find/(.+)/?in/(.+)/(.+)/ /page.html?&type=$1&city=$2&state_abbrev=$3 [L,QSA]
The rewrite works fine if I have a URL that contains all the parameters specified for example: http://www.site.com/find/doctors/in/dallas/tx/
The issue is, I would like to have this rewrite work even if one of the parameters is missing. For example, if I only entered http://www.site.com/find/doctors/ I would still want it to redirect to 'page.html' and just not have the parameters completed. So in that case it would be writing to http://www.site.com/page.html?type=doctors&city=&state_abbrev=. Currently, if I type in a URL that doesn't have all parameters in it the RewriteRule will not work. Any ideas how to fix this issue?
Thanks in advance...
Replace your rule with this:
RewriteRule ^/?find/([^/]+)(?:/in/?([^/]*)/?([^/]*)/?)? /page.html?type=$1&city=$2&state_abbrev=$3 [L,QSA]
There is nothing stopping you from having multiple rewrites. I have many in my .htaccess for different things and many times you have to. Not one rewrite will work for all occasions.
You could try this.
RewriteEngine on
RewriteRule ^find/(.*)/in/(.*)/(.*) page.html?type=$1&city=$2&state_abbrev=$3&%{QUERY_STRING} [L]
RewriteRule ^find/(.*) page.html?type=$1&%{QUERY_STRING} [L]
It will first look for the full URL
http://www.site.com/find/doctors/in/dallas/tx
Then forward it to the first Rewrite rule.
But then if you used this
http://www.site.com/find/doctors
It will skip the first rule and it will match the 2nd rule redirecting to just the partial query string.
Hope that helps but you can make as many rules or conditions you want. And the order in which they come does matter.
I have a query string like
search.php?id=12&keyword=abc&api=gIUTG6898
And I want the URL to be like this:
search/?id=12&keyword=abc&api=gIUTG6898
Now I found a lot of solutions but they are limited to only one variable in the query string. Thanks in advance
It's not that complicated, since you just want to 'transfer' the query string. You can ignore it in the RewriteRule.
RewriteRule ^search/?$ search.php [QSA]
This just rewrites 'search/' to 'search.php'.
Since you are wanting to remove the .php and replace it with a slash, you'd need to reverse Floern's RewriteRule somewhat:
RewriteRule ^/search.php$ /search/ [QSA,L]
I'm trying to mask a part of my url using .htaccess but I'm having several issues
my url is
http://ristorantitalianetwork.com/ristorantitalianetwork.com/admin/
I'd like to remove the duplicate ristorantitalianetwork.com, so I'd like that my url will be like
http://ristorantitalianetwork.com/admin/
I've used
RewriteRule ^ristorantitalianetwork.com/([^/]*)$ ?q=$1 [L]
but it doesn't work
Could you please help me to figure out how to solve this problem?
Thanks a lot
Best regards
You really need
RewriteRule ^/admin$ /ristorantitalianetwork.com/admin [L]
Bear in mind that the URL you should expose to users is http://ristorantitalianetwork.com/admin/ which will then internally get converted (rewritten) to http://ristorantitalianetwork.com/ristorantitalianetwork.com/admin/.
It is not the other way round as many believe.
You almost did it! But...
In your question, your rewriterule says that it is applied on URLs that don't end with a slash (/). And you say you want to rewrite some URLs... and give URLs examples with a slash (/).
If you need to do a real redirect (i.e. the URL in the browser changes):, here's the good rewriterule:
RewriteRule ^ristorantitalianetwork\.com/([^/]*)/$ /$1 [QSA,R=301,L]
If you need to do only internal redirect:
RewriteRule ^ristorantitalianetwork\.com/([^/]*)/$ /$1 [QSA,L]
Keep in mind that the URL must end with a slash (/).
I am trying to rewrite URLs ending like (not only exactly equal to) this:
comments/The-Latest-Out-of-Pakistan/68
into URLs ending in this:
comments/index.php?submissionid=68
Below is what I have in the .htaccess file, but it's not working.
RewriteEngine On
RewriteRule ^comments/([A-Za-z0-9-]+)/([0-9]+)?$ comments/index.php?submissionid=$2 [NC,L]
Any idea why it's not working?
Thanks in advance,
John
I think the only issue is that you've not escaped the hyphen in the character class [A-Za-z0-9-]+, try replacing it with this [A-Za-z0-9\-]+ and see if that works. If not, we can work from there.
I tested it and this one works:
RewriteEngine On
RewriteRule ^comments/([a-zA-Z0-9-]+)/([0-9]+)?$ comments/index.php?id=$2 [NC,L]