.htaccess RewriteRule - .htaccess

I'm trying to write a rewriteRule (with no luck) that would take the string after the hash and rewrite it as a querystring parameter. Something like this...
http://www.example.com/locations/new-york#7F1A6245-3BE3-62D5-A4B6-60C5D599BF21
and rewrite to this...
http://www.example.com/locations/details.aspx?id=7F1A6245-3BE3-62D5-A4B6-60C5D599BF21
I'm using iis7 with .htaccess file, so I'm pretty sure it's the same regex that you would use for .htaccess with apache. Thanks for the help!
EDIT
Based on Ulrich Palha's answer here's what I did...
RewriteRule ^/locations/(.*)/(.*)$ /locations/details.aspx\?id=$2 [NC,L,U]
...and that works like a charm. Thanks Ulrich!

Unfortunately, you cannot do this. The fragment identifier is not transmitted to the server. From Wikipedia
Clients are not supposed to send URI-fragments to servers when they retrieve a document
Therefore you will not be able to process it on the server side...

Related

How can I use .htaccess to redirect a dynamic URL to another Dynamic URL?

I've looked around and my web knowledge is basic. I'm trying to make a dynamic URL link to another-- that is, where one part of the URL can be different.
In this case, I'm trying to make (With my URL scrubbed to some generic one as not to break any rules, here):
https://theurl.com/news/fullnews.php?fn_id=33
TO
https://www.theurl.com/index.php?fn_mode=fullnews&fn_id=33
Where the 33 is a number that can be different based on the article linked.
Thanks any help that can be provided! I've tried editing some similar scripts but seem to not know quite what I'm doing.
This probably is what you are looking for:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^fn_id=(\d+)$
RewriteRule ^/?news/fullnews\.php$ /index.php?fn_mode=fullnews&fn_id=%1 [END]
You need to enable the interpretation of distributed configuration files (".htaccess") for this and obviously the rewriting module needs to be loaded and enabled in the http server.
Much more elegant and preferred for SEO reasons however would be to use a URL like that:
https://example.com/fullnews/33 or https://example.com/news/33
Which could be achieved by those rewriting rules:
RewriteEngine on
RewriteRule ^/?fullnews/(\d+)$ /index.php?fn_mode=fullnews&fn_id=$1 [END]

Hiding some GET parameters from URL

I am redirecting page using PHP header location:
Current URL in browser
https://mywebsite/open/firstpage/php/start.php?&cnt=us&language=en&url=http://secureURL.com
but want to show
https://mywebsite/open/firstpage/php/start.php?&cnt=us&language=en
I am using GET method on the other side to collect all variables. I have to hide &url in querystring but want to receive it on other side $_GET['url']
How can I share my &url without showing in URL querystring? HOw can I write htaccess?
Redirect for all URLs
RewriteEngine on
RewriteRule ^(.*) $1?%{QUERY_STRING}&url=http://secureURL.com [L]
Redirect for only /open/firstpage/php/start.php
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/open/firstpage/php/start.php
RewriteRule ^(.*) $1?%{QUERY_STRING}&url=http://secureURL.com [L]
I think this is what you want.
You can't do that. If a parameter is not present in the query string, it won't be available anywhere, it's just not there. There's no such thing as "hiding" the query string.
You could, however, use some form of session mechanism to pass a piece of data from one page to another. You could put it in the $_SESSION, or use cookies. There may also be a way to achieve this through really arcane mod_rewrite magic, but you shouldn't go down that route. Really.
More importantly: what are you trying to achieve? Why are you trying to do this?
Aesthetic reasons? Then be aware that modern browsers tend to hide the query string part of the URI from the user.
Security reasons? Then you're doing it horribly wrong, you shouldn't use something so easily manipulated by the client.
User tracking? There are established solutions out there for that (say, Google Analytics).

.htaccess custom RewriteRule for Symfony2

I need to maintain the mapping of old urls in a new Symfony2 application, (without redirection). But I'm going crazy on the RewriteRule...
I just want something really simple:
Supposed the public url domain.tld/info-cookies.html should be mapped to a specific route let say domain.tld/information-cookies
I have the following rewrite:
RewriteRule info-cookies.html$ /app.php/informations-cookies [NC,L]
But no matter what we try, we can't succeed to achieve this.
I am missing something there ?
Sorry for the noise, it was the path_info which is not taking in account by Symfony2 ;) Only the real url...

Too many Rewrite Rules in .htaccess

I had to redesign a site last week. The problem is that last urls weren't seo friendly so, in order to avoid Google penalizing my site because too many 404 errors, I have to create a lot of Rewrite Rules because all the content had awful URL's ( and that content had a good position on SERP's).
For example:
RewriteRule ^documents/documents_for_subject/22-ecuaciones-exponenciales-y-logaritmicas http://%{HTTP_HOST}/1o-bachillerato/matematicas-cc.ss/aritmetica-y-algebra/ecuaciones-exponenciales-y-logaritmicas [R=301,L]
Is this a problem on my performance? Is there another solution to my situation?
Thanks
They are in the same domain.
Then an internal redirect is much better. A header redirect sends the new URL to the browser and causes it to make a new request; an internal one is handled, as the name says, internally.
This should work:
RewriteRule ^documents/documents_for_subject/22-ecuaciones-exponenciales-y-logaritmicas /1o-bachillerato/matematicas-cc.ss/aritmetica-y-algebra/ecuaciones-exponenciales-y-logaritmicas [L]
Any performance issues are going to be negligible with this - except maybe if you have many thousands or tens of thousands of individual rules, those may slow down Apache. In that case, if you have access to the central server configuration, put the rules there instead of a .htaccess file, because instructions in the server config get stored in memory and are faster.
A. Yes using 301 is the right way to notify search bots about changed URLs and eventually your old URL's will be removed from search results.
B. You don't need to use %{HTTP_HOST} in your rewrite rule just use it like this:
RewriteRule ^documents/documents_for_subject/22-ecuaciones-exponenciales-y-logaritmicas http://%{HTTP_HOST}/1o-bachillerato/matematicas-cc.ss/aritmetica-y-algebra/ecuaciones-exponenciales-y-logaritmicas [R=301,L]
C. If you have lots of RewriteRules like above I recommend using RewriteMap or else use some scripting support (like PHP) to redirect from old to new URL with 301.

.htaccess redirect URL to sub-part of URL

I would like to redirect URLs (100's of them) of a site based on a pattern match.
So for example if the requested url is
http://www.example.com/showcase/properties/boston/page/1
I would like to redirect it to
http://www.example.com/showcase/properties/boston
i.e. remove the /page/1 from the actual url.
I am newbie with all .htaccess concept. So if I have missed any information to add please let me know. Also I would appreciate if somebody can point me to a nice tutorial/book for .htaccess learning.
Thanks very much in advance.
P.S. - The site is built using PHP language.
RewriteRule (.*)/page/(\d+) $1
I don't know any tutorial about .htaccess!
I have apache manual on my PC and I use it!

Resources