Fake Htaccess Url - .htaccess

I need to "fake" rewrite the url.
For example, when the user access: http://website.com/PAGE.html, it shows the http://website.php/handle.php?page=PAGE, but the url still remains website.com/PAGE.html ( mention: PAGE.html does not exists on the server, PAGE can be replaced with any string )
Only for the .html extensions I want this fake redirect.
How to do ?
I tried with :
RewriteEngine on
RewriteRule ^/(.*).html /handler.php?key=$1 [L]
But no result.

Related

remove everything from a url redirect to doc root

I have a url say https://example.com/index.php/foo/bar
I want any page in example.com to goto https://example.com
I want the browser to update with the home url. this is for any url to hit this site. This could include urls with query ie https://example.com/?foo=bar. Literally all/any pages to go to the home page regardless
I've tried numerous RewriteRules Redirects and none do what i want (the nearest is to load index.php but the url is still wrong)
I'd like to use .htaccess but if easier in .conf file I'd do that
Just thinking I could do this in the index.php file by checking reloading the page with header if it has a query on it. would this be recommended?
I'm using ubuntu 16.04 apache 2.4 and i have php 7.1 with all mods enabled to handle redirection and rewrites (site had wordpress on it but now contains a coming soon page and nothing else)
current but not working version in htaccess is
RewriteEngine On
RewriteBase /
# Make sure there is a query string
RewriteCond %{QUERY_STRING} .
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /? [R=301,L]
this will correctly load a url with a query string (https://example.com?foo=bar) but the browser doesn't update the redirected url/ if I use https://example.com/index.php/foo/bar scripts and images in the index.php are not loaded and as with query strings the url remains unchanged in the browser.
adding the following to the top of my index.php resolved my issue without needing edits to .conf or .htaccess files
if ( $_SERVER['REQUEST_URI'] != '/index.php' ) {
header("Location: /index.php");
exit(0);
}

htaccess code to encode URLs with different page name

the below htaccess code work for single URL with same page
RewriteRule ^([^/]*)\.html$ /current/shoppe/sub-category.php?category=$1 [L]
now, i need to rewrite a URL of another page.

CakePHP redirect .php to controller

My old website URL structure was something like this:
http://www.example.com/index.php?go=archives&data=lastweek
Today, I migrated to CakePHP, so that URL won't work. So I want to redirect it to this URL:
http://www.example.com/archives/find?data=lastweek
(I don't want to change query string to action parameter, for some reason, I should keep it as a query string.)
What should I do? (edit which .htaccess file? CakePHP has 3 files!)
In the htaccess file in your document root (preferably above any rules that may already be there), add these:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^go=archives&data=([^&]+)
RewriteRule ^/?index.php$ /archives/find/?data=%1 [L,R=301]
This should 301 redirect /index.php?go=archives&data=anything to /archives/find?data=anything.

htaccess redirect page but do not show file

I have a page which I'm redirecting using PHP:
header('Location:notices.php');
exit;
Is it possible to hide the page name entirely using .htacess? So instead of the browser showing the URL http://example.com/notices.php, it instead shows http://example.com but in effect it really loadedhttp://example.com/notices.php.
I'm open to any other solution since my goal here is just to not show the actual page being loaded.
EDIT: The browser still loads notices.php (not /index.php) but the URL shows /. Only the URL changes, or in this case, masks the file being loaded.
notices.php:
<?php
include('index.php');
exit();
doing a header() redirect WILL show the new url in the browser. That's unavoidable. You've told the browser "go over there", so it obediently does.
The other option is to use mod_rewrite to silently rewrite requests for /notices.php into a request for /index.php.
Add the following to your .htaccess file in the root folder of example.com
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.+)?\.example.com [NC]
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule . notices.php [L]
All requests to example.com will show notices.php, if this is what you really want.

strip utm_source from url by htaccess then redirect to origin url

I have issues with URLs of website.
I have check the server and referrers, then see a lot of strange URLs with some addition var added to original. That may effect the SEO and server load to create those pages.
eg:
Original:
xaluan.com/modules.php?name=News&file=article&sid=123456
xaluan.com/modules.php?name=News&file=article&sid=123987
Someone access my web page by url
xaluan.com/modules.php?name=News&file=article&sid=123456&utm_source=twitterfeed&utm_medium=twitter
xaluan.com/modules.php?name=News&file=article&sid=123987&utm_source=twitterfeed&utm_medium=twitter
I need one .htaccess that can redirect all 301 URLs which have utm_source=twitterfeed&utm_medium=twitter to original one.
You could try this:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^((.*?)&|)utm_
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1?%2 [R=301,NE,L]
It will drop everything from the Querystring after the first utm_.

Resources