I have an address: www.domain.com/index.php?category=this-is-me#!
For some reason google directs to this address.
I want to redirect my users to www.domain.com/index.php?category=this-is-me
How can I do that?
I don't think the "#!" is needed.
I work with htaccess files (php, apache).
Thanks
You can't do anything about it in htaccess files, in php, or in apache. Everything starting from the # is called the URI fragment and it is never sent to the server. So apache doesn't even know it's there.
What you'll need to do is use something that's on the client-side (e.g. browser) to remove it. For javascript, see something like this: Remove fragment in URL with JavaScript w/out causing page reload
Related
i would like to make it impossible to open a PHP file directly through an Url but keep it still accessible through jQuery. Right now it is possible to enter this URL in the Browser:
http://domain.com/php/member.php
But i would like to prevent that. If someone types this in the Browser Url than i would like to redirect everyone to http://domain.com with htaccess. But it must be still possible to send variables through the own Website with jQuery to the PHP File.
Thanks :)
If you don't want it access directly put it outside the web root and use a php script to interact with it. jQuery/JavaScript is client side. If it can access the file, then the client will be able to also. You would be better off using PHP to send/receive info to jQuery and hide that file outside the web root so there is no direct access.
You can use this htaccess redirect to generate the code to redirect domain.com/php/member.php to domain.com. You can use a 301 redirect like the one above.
I want to redirect a URL containing a hash to another URL.
Example: example.com/#test should redirect to example.com/teste_page
Can this be done using the .htaccess file?
Yes it can be done, just use the No Escape flag... [NE,R,L]
No, hashes are never sent to the server, they are in-page fragment identifiers, so only used by the browser. So you're .htaccess would never have access to the hash. You'd have to do some nifty redirects to get that info to your server.
Here are some ideas that might spark something:
http://forum.modrewrite.com/viewtopic.php?t=3912
This cannot be done with .htaccess - as far as the browser is concerned, the # and anything following it does not need to be sent to the server, as it's a link for the browser to resolve.
Here's a related question, as well as an example:
Note google thinks the request was:
http://www.google.com/thisisa404?query=string#fragment
I need some help writing a .htaccess file.
I'm using a Flash based theme and it creates URLs like this:
http://www.mysite.com/#/pagetitle
How can I redirect these to:
http://www.mysite.com/pagetitle
?
Apache (and anything that runs serverside) can not access anything after #; that part is the fragment and available to client side only (JavaScript).
You will need to use JavaScript to access that programmaticly.
I'd like to know how websites have created URLs with other domains like these on trafficestimate.com.
I'm guessing it's some .htaccess stuff to redirect domain names to a dynamic page?
Thanks
Your URL has an GET Request. So when someone calls the page http://google.com/search with the parameters hl=en, safe=off etc., the page can process those parameters. So for instance safe=off means that you want to get back any search result. The q=site:... is your search string. In this case Google will look it up in its database and give you the results. So when you call this URL there is probably no .htaccess processing done. However you can process the URL and GET request with .htacces and i.e. redirect the user to another page.
Maybe you'll describe a bit further what exactly you trying to do/want to know. This makes explaining easier.
EDIT: After reading Gumbo's comment I looked at the Google result page. So maybe your question means the trafficestimate-URLs. They look like http://trafficestimate.com/example.org. This is really a good case for .htaccess. So using .htaccess they take the URL and redirect it to http://www.trafficestimate.com/websites/?domain=example.org. Here you have again a GET request and an application builds the page.
Some URL rewriting is probably involved. Otherwise they would have to create an existing file for every possible request.
Using Apache’s mod_rewrite in a .htaccess file is one option. But since the server identifies itself with “Microsoft-IIS/7.5”, they are probably rather using ISAPI_Rewrite, a mod_rewrite derivative for Microsoft’s IIS.
In my application users have their own "websites" which can be reached if they are signed in.
However, since these websites are just directories containing html and other documents everyone in the world can reach them if they know the address. I can't have that :) A user should be able to decide whether or not thw world might see their files or not.
Can I use .htaccess to activate a PHP-script every time a request is made to that directory?
I.e. if reqested-site is "/websites/{identifier}", run is-user-allowed-to-view.php?website={identifier}
The identifier is a numeric value which refers to both a physical folder and a post in the database... and the script would then return true or false.
Or is there perhaps another way of solving the same issue?
Cheers!
You can use mod_rewrite to rewrite requests with such a URL internally to your script:
RewriteEngine on
RewriteRule ^website/([0-9]+)$ is-user-allowed-to-view.php?website=$1
But this rule is only for the URL path /website/12345 and nothing else.
Or have every page as a PHP page and just put at the top a single line to redirect if the session / cookie is incorrect or not set. Obviously wouldn't work for non-PHP content such as images.
What you need is a proper front-end (written in whatever language). You need to have your web-server (Apache in your case it seems) pass the requests to the said front-end.
You cannot do what you are asking for with just .htaccess files.