.htaccess custom RewriteRule for Symfony2 - .htaccess

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...

Related

Generating friendly URLs / htaccess from database

The scenario
I have a menu builder (Title, Link...) in PHP/MySQL, which I want to be able to configure the friendly SEO rule in the .htaccess
The issues
Here is a typical rewrite rule at the moment:
RewriteRule ^computer/other-components/?(.*)$ index.php?CategoryID=9&SubCategoryID=2 [NC,L]
I could write all these manually in the .htaccess but there are a couple of issues:
I would have to manually do this each time I want to add/make changes to the page structure
It's really long.
I've read that writing directly to the .htaccess is a no-no for security, so what would be best to implement something like this? Wordpress and similar CMSs do similar, so what is recommended here?

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).

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 RewriteRule

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...

Unable to show siteA's content at siteB by domain masking

I have a domain www.siteA.com, which uses Joomla, while the domain www.siteB.com is empty.
I would like to show the content of the domain www.siteA.com at www.siteB.com.
I tried to solve the problem first by making a domain redirection by .htaccess, but I could not show SiteA's content at SiteB.
How can you show the contents of mysiteA.com at mysiteB.com by domain masking in .htaccess?
You really should be doing this by CNAME-ing the domain, but if you really want to use .htaccess you can do what #Unkwntech suggests
Edit: It would just look like
www.siteB.com CNAME www.siteA.com
Whichever way you do it (CNAME or htaccess) you're probably going to get an SEO penalty for duplicate content.
RewriteEngine On
RewriteRule ^.*$ http://www.siteA.tld/$1 [NC]
This should rewrite every request to siteA.

Resources