Rewrite URL for 2 queries - url

I can't figure out how to have two queries in a URL rewrite.
I know that the following will allow me to have a single query.
RewriteRule ^movie/(.+)$ movie.php?url=$1
example.com/movie/superman
but how would i add another query in there?
example.com/cinema/vue-sheffield/movie/superman
everything i do seems not to work.
Thanks

If your cinema is always sheffield you can do this.
RewriteRule ^cinema/vue-sheffield/movie/([^/]+) index.php?movie=$1&cinema=sheffield&%{QUERY_STRING} [L]
if not then you can do this
RewriteRule ^cinema/([^/]+)/movie/([^/]+) index.php?cinema=$1&movie=$2&%{QUERY_STRING} [L]
Then you can have
example.com/cinema/whateverhere/movie/somemovie

That is not necessarily a query, that depends on the web service you're talking to – the stuff coming after the ? is the URL parameter list, and you can have multiple URL parameters in there separated by &. Usually, the order or parameters doesn't matter, and more often than not, you'll find them in the form ?foo=bar&etc=whatever.
I'm not sure though what your question on rewrite is.

Related

rewrite and url decoding

It seems a site is linking to mine in a bad way.
From google webmaster tools I see some 404 errors
domain.com/file.php?id=1 (404) Not found (Date)
This url works ok but because of browser page decoding, the real (404) url is
domain.com/file.php%3Fid%3D1 (this is what my browser displays in the url input when I click on google url)
My first try was
RewriteRule ^(.*)\%3F(.*)$ $1?$2 [R=301, L]
to change %3F to '?' but it does not work. It is confusing what is real and what is en/decoded.
Thanks
Hmm, try this:
RewriteRule ^(.*\%3F.*)\%26([^%]*)(\%3D)?(.*)$ $1&$2=$4 [N]
RewriteRule ^(.*)\%3F([^%]*)(\%3D)?(.*)$ $1?$2=$4 [R=301,L]
EDIT: I see you already tested for %3F... if that didn`t work, then something else might be up.
It is not an elegant solution, but after months, it is the only way I found.
Regular case
domain.tld/dir/file.php?id=UID&qty=NUM&... (from old site structure)
is rewritten as
domain.tld/newfile.php?id=UID&qty=NUM&... [R=301,L]
So, for requests like
domain.tld/dir/file.php%3Fid%3DUID%26qty=NUM%26... (from old site structure)
I perform
RewriteRule ^dir/file\.php(.*)$ script.php?qs=$1 [R,L]
This MUST be AFTER all directives that involves dir/file.php
Then I can handle the query string $_GET['qs'] in script.php
It may not apply to other situations that would enter into a loop or undesired results.
use [NE] flag in your RewriteRule

A little bit help in url rewriting, please!

I have a short question about url rewriting...
I have a website. Let's say http://www.example.com/
with some subsites:
http://www.example.com/a.php
http://www.example.com/b.php
etc...
and some "special" urls like
http://www.example.com/c.php?i=1#link1
http://www.example.com/c.php?i=1#link2
http://www.example.com/c.php?i=2#link1
Now I would like to write a .htaccess file to convert current urls into rewritten urls like
http://www.example.com/a/
http://www.example.com/c/1/#link1
I'm not an expert in url rewriting, so could somebody please help me?
Best reagards.
RewriteRule ^a$ a.php [L]
RewriteRule ^c/(.*)/(.*) c.php?i=$1$2
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^a.php a/
RewriteRule ^b.php b/
Should work as far as your static pages go, you can not rewrite the hash because the hash is not sent to the server (as discussed here). If you need to rewrite the hash I would suggest changing the hash to another GET variable (eg u), in that case just add this to your htaccess: RewriteRule ^c.php?i=(.*)&u=(.*) c/$1/$2. If you simply intend to leave the anchor though, you can omit it from your rewrite and everything should be fine (...becuase the server never sees the hash/pound symbol), and in that case you should add this to your code RewriteRule ^c.php?i=(.*) c/$1/.

.htaccess php progress

Thanks to the people that've helped me so far with this, I'm ready for the last step, I think.
I've got my URLs looking like this.
/brochure.php?cat_path=35&name=concrete-intermediate-posts
This is great and finally I just need to know how to turn that URL into this desired URL:
/brochure/35/concrete-intermediate-posts
Just like the Stack Overflow format.
Could anyone help me with the correct .htaccess rule?
Also, if I have other get variables in other sections, will this re-write harm them? (they use different variable names)
Thanks
With mod_rewrite you will rather do the opposite: rewrite a URL path like /brochure/35/concrete-intermediate-posts internally to /brochure.php?cat_path=35&name=concrete-intermediate-posts:
RewriteRule ^([^/]+)/(\d+)/([^/]+)$ $1.php?cat_path=$2&name=$3 [L,QSA]
The other side, using a URL path like /brochure/35/concrete-intermediate-posts instead of /brochure.php?cat_path=35&name=concrete-intermediate-posts in the HTML documents, would be done with PHP.
I Hope you mean something like this:
RewriteEngine On
RewriteBase /
RewriteRule ^brochure/([0-9]+)/([-a-zA-Z0-9]+)$ /brochure.php?cat_path=$1&name=$2 [L]

MVC url Rewriting something like http://controller.website.com

Using MVC. Is there a way to make any url like .example.com to point to example.com/user/
as in http://marwan.example.com to point to example.com/user/marwan
The controller is user and the action is index which takes marwan as its variable.
One idea I had is to make a custom error page to handle 404 and see if the url starts with something like *.example.com and redirect to the proper controller. There must be a better way to do this!
Take a look at this answer it may help you out.
ASP.NET URL Rewriting
You can try the following:
RewriteConf %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/user/%1$1
RewriteRule ^/user/([a-zA-Z0-9]+)\.example\.com/(.*) http://example.com/user/$1/$2 [NC,L]
What this rule does is first insert the host into the URL path and then strip out the correct values from the host and write it the way you want on the backend.

Mod_rewrite - how to 301 redirect an old URL to a new one

I need to grab some of my website's old URLs and do a 301 redirect to the new ones, since they are already indexed and we don't want to loose relevance after the change. The old URL is in fact very ugly and for some reason everything I try to do to rewrite it does not work. Here it is:
http://www.mywebsite.com/ExibeCurso.asp?Comando=TreinamentoGeral&codCurso=136&Titulo=Como%20Estruturar%20um%20Sistema%20Gerencial%20de%20Controles%20Organizacionais,13
Basically, I need to translate it into something like:
http://www.mywebsite.com/curso/136
From the old URL I need to check if the user typed "ExibeCurso.asp"; then I know I must send him here: /curso. I must also grab the integer that was in the querystring parameter "codCurso" (136). What is the regular expression I must use for this. I am using ISAPI_Rewrite 3, which basically implements htaccess on IIS, so there should be no difference in terms of syntax. Thanks.
Try this rule:
RewriteCond %{QUERY_STRING} ^([^&]*&)*codCurso=([0-9]+)(&.*)?$
RewriteRule ^/ExibeCurso\.asp$ /curso/%2? [L,R=301]
But I’m not sure whether ISAPI Rewrite requires the pattern to begin with a slash.
Off the top of my head, something like this should work:
RewriteRule ^ExibeCurso.asp(.*)$ http://www.mywebsite.com/curso/$1 [L,R=301]
That would at least send the traffic to /curso/ with all parameters attached. Maybe it's best to process it from there.

Resources