My URL Syntax Now is Like
http://20percents.com/au/restaurant/?shop=Fantasia%20MacArthur%20Central
And, how can I rewrite it to like
http://20percents.com/au/Fantasia-MacArthur-Central
Remove restaurant from url, remove ?shop from url, and change the %20 to -
I tried like
RewriteEngine on
RewriteRule ^restaurant/([^/\.]+)/?$ restaurant?shop=$1 [L]
This didn't work
I also tried like, and this too didn't work.
RewriteCond %{QUERY_STRING} val
RewriteRule ^/restaurant/?shop
Thanks
Related
I am currently updating our website and want to redirect from old url's to the new ones. I appliled several rewriterules to get nice urls without query strings for the new pages, this works perfectly. But i ran into problems when trying to do the following:
I want to change an url's query string from
www.domain.com/?content=foo
to
www.domain.com/index.php?content=bar
or even better, rewrite directly to the new , nice url i have already generated by rewrite rules:
to
www.domain.com/niceurl
in the .htaccess file using a RewriteRule.
I tried this:
RewriteCond %{QUERY_STRING} content=foo
RewriteRule content=bar$ content=foo [L]
or
RewriteCond %{QUERY_STRING} content=foo
RewriteRule niceurl$ content=foo [L]
and a lot of other variations, i just can't get it to work. Any ideas?
If you want to redirect, i.e. tell the client to forget about the old URL and fetch the new shiny URL instead, you must look for the old one (RewriteRule pattern / and RewriteCond QUERY_STRING) and then redirect R to the new URL
RewriteCond %{QUERY_STRING} content=foo
RewriteRule ^$ /niceurl [R,L]
So I have a kind of strange trouble. I have a rewrite rule from
mysite.com/brand.php?brand=example&ref=ex1
to
mysite.com/brand/example/ex1
And I managed to do that, but there is also another problem: when you type this:
mysite.com/brand/example/ex1.html
or
mysite.com/brand/example/ex1.php
I get this:
mysite.com/brand/example/ex1?ref=ex1.php&brand=example
Can anyone tell why I get this redirect and how to get rid of it?
I tried this:
RedirectMatch ^brand/([A-Za-z0-9-\.\_]+)/([A-Za-z0-9-\.\_]+)php$ /brand/$1/$2
or this:
RedirectMatch ^brand/([A-Za-z0-9-\.\_]+)/([A-Za-z0-9-\.\_]+)\.php$ /brand/$1/$2
but it simply doesn't work.
Please, anyone help me!
I would use the mod_rewrite for this:
RewriteEngine On
RewriteCond %{REQUEST_URI} =/brand.php
RewriteCond %{QUERY_STRING} ^brand=([^&]+&ref=(.+)$
RewriteRule .* /brand/%1/%2? [L,R]
The RewriteRule is applied only when both RewriteCond are valid. The first RewriteCond compares the request URL to be /brand.php, the second matches regular expression against the query string and stores the matches in %1 and %2 respectively.
In the RewriteRule is the URL rewritten using the matched parts from query string.
first, sorry for my bad English.
I try to rewrite url generated from Form Get and redirect that.
my url is like this:
http://www.mysite.com/properties?action=search&agreement=for-rent&category=my-category&type=&zone=my-zone&city=my-city
and I have this .htaccess configured:
11. RewriteCond %{QUERY_STRING} ^action=(?:[a-zA-Z\-]*)&(?:.*)=([a-zA-Z\-]*)&(?:.*)=([a-zA-Z\-]*)&(?:.*)=([a-zA-Z\-]*)&(?:.*)=([a-zA-Z\-]*)&(?:.*)=([a-zA-Z\-]*)$
12. RewriteRule (.*) %{REQUEST_URI}/%1/%2/%3/%4/%5/? [R=301,L]
So basically all my request are direct to index.php.
21. RewriteCond %{REQUEST_URI} !index\.php|resources|hidden
22. RewriteRule ^(.*)$ index.php/$1 [L]
All works, but the problem is when I have an empty value in query string, the rule add double slash and the above url (for example whit &type=&zone=my-zone... type have empty value) will translate like that:
http://www.mysite.com/for-rent/my-category//my-zone/my-city/
The question is: How can i remove in .htaccess the double slash generated if i have one or more empty value in query string?
Thanks
Easiest is to do another redirect (not real pretty as it requires two 301's).
RewriteCond %{THE_REQUEST} //
RewriteRule .* $0 [R=301,L]
The fun part is that when the url is loaded with a double slash in it, mod_rewrite will automatically remove this. So as you can see above you'll just have to rewrite the url to itself, kind of.
I'm trying to rewrite urls like http://www.url.com/blog/?p=123 to http://www.url.com/#blog/123. I've read up on things and found that you can only parse the query string in the RewriteCond so I tried something like:
RewriteCond %{QUERY_STRING} ^p=([0-9]*)$
RewriteRule ^.*$ /#blog/%0 [NE,R]
When I try this the urls end up being rewritten to:
http://www.url.com/#blog/p=213?p=213
Any ideas how to do this properly? Also, is there a way to add an additional RewriteCond that checks that the REQUEST_URI contains blog?
You can do this by removing the query string entirely:
RewriteCond %{QUERY_STRING} ^p=([0-9]*)$
RewriteRule ^.*$ /#blog/%1? [NE,R]
This should give you:
http://www.url.com/#blog/213
If you want to check if the URL contains the term "blog" then simply check:
RewriteCond %{REQUEST_URI} .*/blog/.*
It is important to note that you will not be able to check for "blog" in links like http://www.url.com/#blog because, as noted by Patrick, everything after the # is not sent to the server.
See the Apache wiki on mod_rewrite for more information.
That may not work because browsers do not send the fragment of the url after the hash (#) with the request, so any request for http://www.url.com/#blog/p=213?p=213 will be a request for http://www.url.com/
The hash fragment is supposed to be used for anchor tags on pages, and is never sent to the server.
Try this rule in your .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{QUERY_STRING} ^p=(.*)$ [NC]
RewriteRule ^blog/?$ /#blog/%1? [NC,NE,L,R]
With above a URL of http://localhost/blog/?p=1234 will become http://localhost/#blog/1234
I have a news (blog) site that returns urls in the following format when individual posts are selected:
website.net/sitenews.php?q=posts/view/postname/12
I am seeking to rewrite the url so that it reads:
website.net/sitenews.php/posts/view/postname/12
or any other way where the ?q= is removed for purpose of removing the ? so that the url can be accessed by facebook's like button as the facebook url linter does not parse query strings.
In the htdocs .htaccess file in the root directory I have tried the following:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} q=
RewriteRule (.*) website.net/sitenews.php/$1? [R=301]
This successfully removes the q=? however the rest of the string (posts/view/postname/12) is not returned and the url now looks as follows:
website.net/sitenews.php/sitenews.php
Does anyone have any suggestions to help me complete this url_rewrite?
Try this instead in your .htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^q=(.*)$ [NC]
RewriteRule ^(.*)$ /$1/%1? [R=301,L,NE]
R=301 will redirect with https status 301
L will make last rule
NE is for no escaping query string
%1 is capture group for query string q= (whatever comes after q=)
$1 is your REQUEST_URI
If you are using any CMS, like wordpress, or joomla or SE, then you have option to do that else you need to have an .htaccess file where you can write the code, refer this links
http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html
http://www.webmasterworld.com/forum92/2545.htm
http://www.google.com/#sclient=psy&hl=en&q=htaccess+change+the+url&aq=0p&aqi=p-p1g4&aql=&oq=htaccess+&pbx=1&bav=on.2,or.r_gc.r_pw.&fp=c875dd2b8adea15a