Im trying to do a multi language errordocument on my htaccess.
But it doesnt enter to my original 404 error page or it just only goes to one of the error pages.
i just want to check the folder and if the folder is "pt", it goes to the portuguese 404error page, else it goes to the other pages with the correspond language.
i already tryed more example but non have help me.
In below there some code that i had already tryed.
Try #1
ErrorDocument 404 http://www.teleondagroup.com/novosite/Teleonda/
RewriteRule ^([a-z]{2}) $1/404error.php [L]
Try #2
RewriteRule ^(pt)/ /$1/404error.php [R,L]
ErrorDocument 404 http://www.teleondagroup.com/novosite/Teleonda/pt/404error.php
RewriteRule ^(en)/ /$1/404error.php [R,L]
ErrorDocument 404 http://www.teleondagroup.com/novosite/Teleonda/en/404error.php
I already solve the problem with this site.
https://webmasters.stackexchange.com/questions/47974/separate-404-page-for-subdirectory
You can use something like the following :
RewriteEngine on
#if a file or directory doesn't exist in a particular folder
RewriteCond %{DOCUMENT_ROOT}/$0 !-f [OR]
RewriteCond %{DOCUMENT_ROOT}/$0 !-d
#redirect the request to /errorpage.php in that folder
RewriteRule ^([^/]+)/.*$ /$1/errorpage.php [L,R]
This will Redirect a 404 Uri to /errorpage.php file located in the requested directory ie . example.com/demo/brokenlink.php to example.com/demo/errorpage.php .
Or if this is just for a single directory /pt you can use the following :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?pt.*$ /pt/errorpage.php [L,R]
I would like to redirect all URL having a trailing slash referenced by google to the new url without a trailing slash.
Example :
http://example.com/toto/ ===> to http://example.com/toto
Warning I already rewrite the rule to avoid the .html extension also !
Here is my existing code :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
RewriteCond %{REQUEST_URI} (.+)$
RewriteRule ^ %1 [R=301,L]
</IfModule>
I got the following error :
Not Found
The requested URL /example/.html was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
The objectif of the topic was to find a solution to make a redirection of existing URL listed by search engine like google to not lose the current SEO after making a complete refresh of the web site (Wordpress to bootstrap).
The first objective was to redirect all url trafics like http://example.com/toto/ (google) ===> to http://example.com/toto.
Unfortunatly I understood that making the reverse is more powerful to not lose my existing listing on google (sitemap & robots)
So I have decided to review all the code in order to have the following result by deleting the html extension and adding a trailing slash at the end of each url :
http://example.com/toto.html ===> to http://example.com/toto ==> http://example.com/toto/
Below is the code HTaccess that I used to make this possible :
RewriteEngine On
RewriteBase /
# To externally redirect /dir/foo.html to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1/ [R,L]
# add a trailing slash at the end /dir/foo/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [L,R=301]
# delete the extension .html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*?)/?$ $1.html [L,QSA]
I have also added the code line below in each html page to enforce it :
<base href="http://example.com/">
Hoping to help any readers/coders in the same situation
I am beginner in codding. I want make url pretty. I search this question on google then i found i have to use .htaccess. I tried htaccess code.
Here is my URL looklike
website.com/project-details.php?Residential/The-Serenas/1
I want to make url like website.com/Residential/The-Serenas/1
I want to remove entire "project-details.php?" word from url by htaccess.
here is my .htaccess code
Options +FollowSymLinks
RewriteEngine On
RewriteBase /basename/
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /project-details\.php\?([^\s&]+) [NC]
RewriteRule ^ view/%1? [R=302,L]
RewriteCond %{THE_REQUEST} /project-details\?([^\s&]+) [NC]
RewriteRule ^ view/%1? [R=302,L]
# internally rewrites /view/ABC123 to project-details.php?ABC123
RewriteRule ^view/([A-Za-z0-9_#./#&+-]+)$ project-details.php?$1 [L,NC,QSA]
# PHP hiding rule
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
Above htaccess code work and url replacce to website.com/view/Residential/The-Serenas/1
If i remove view from this line RewriteRule ^ view/%1? [R=302,L].
Then page goes to 404 error. If i dont remove view then code worked but view show on url.
I dont want to show anything on url only remove "project-details.php?" this.
This rule is to check the request uri whether is /project-details.php and any query string follow behind, and redirect user to the uri that matches the query string. %1 is the backreference and provide access to the grouped parts (in parentheses) of the pattern, in this case ([^\s&]+). For example, if uri /project-details.php?Residential/The-Serenas/1 is requested, the user will be redirected to /Residential/The-Serenas/1.
RewriteCond %{THE_REQUEST} /project-details\.php\?([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]
This rule is to check if user requests existing file and directory, if not, then the uri is rewritten internally (only server knows the destination uri, user does not know this). For example, if uri /Residential/The-Serenas/1 is requested, the server will rewrite the uri to project-details.php?/Residential/The-Serenas/1.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9_#./#&+-]+)$ project-details.php?$1 [L,NC,QSA]
Update : By the help of answers, I am able to have this update. I want following expression in my .htaccess to be working . (Complete script of .htaccess is shared in question as well)
RewriteCond %{REQUEST_URI} ((mypage2(/\d{4}-\d{2}-\d{2})?/\d{1,2}) |about-us)
RewriteRule ^(.+)$ /subsite/#/$1 [R=301,NC]
Detail Of Question:
I have added angularjs subsite to an exsiting expressionengine php site.
subsite contains only three pages, which were very slow in existing website
I want htacces to redirect those three urls to new subsite urls e.g mydomain/page2/parameter1/parameter2 to mydomain/subsite/#/page2/parameter1/parameter2 and mydomain/page2/parameter1 to mydomain/subsite/#/page2/parameter1
(This is not compulsory) In subsite I want to clean up/manipulate Urls using history push state to show user
mydomain/page2/parameter1/parameter2 instaed of mydomain/subsite/#/page2/parameter1/parameter2
My .htaccess is like
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/#/$1 [L,QSA]
Following is most wanted thing to me
RewriteCond %{REQUEST_URI} ((mypage2(/\d{4}-\d{2}-\d{2})?/\d{1,2}) |about-us)
RewriteRule ^(.+)$ /subsite/#/$1 [R=301,NC] ==> when url is like mypage2(/date optional)/pagenumber then redirect it to subsite/#/mypage2(/date optional)/pagenumber
Also this is optional, I can live if following is not achieved
In my routing.js I want to manipulate urls like
$rootScope.$on('$stateChangeSuccess', function (event, toState, toParams,
fromState, fromParams, options, Data) {
var cleanUrl = window.location.toString().replace(subsite+'/#/', '');
window.history.pushState(null, null, cleanUrl);
//alert("Yes this works, it shows me the required url in browser at this moment");
//Here I am trying to clean the url
//But after that it reloads, some unwanted redirection happens after it
});
Okay, Try with below rule,
RewriteEngine On
RewriteCond %{REQUEST_URI} ^!(aSpecialString2|aSpecialString1|/)
RewriteRule ^(.+)$ /#/$1 [R=301,NC]
Here you will not get the #/uri in url but you will get %23 html entity which will respond as same as # in url and your app will work.
And I am assuming you will get the way to work it out with angular.
You can use mod_rewrite and php in the server side to this task
Create an index.php
<?php
if ( !empty($_GET['id']) ) {
$protocol = 'http://';
if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
$protocol = 'https://';
}
header('Location:' . $protocol . $_SERVER["HTTP_HOST"]. '/#/' . $_GET[id]);
exit();
}
?>
You html here
Add the following in your .htaccess
RewriteEngine On
RewriteBase /
RewriteRule "index.php" - [L]
RewriteRule "^(.*)$" "index.php?id=$1"
To bypass some urls aString1,aString2 you can use:
RewriteEngine On
RewriteBase /
RewriteRule "index.php" - [L]
RewriteCond %{REQUEST_URI} !^(aString1)
RewriteCond %{REQUEST_URI} !^(aString2)
RewriteRule "^(.*)$" "index.php?id=$1"
To bypass assets you can use:
RewriteEngine On
RewriteBase /
RewriteRule "index.php" - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^(.*)$" "index.php?id=$1"
Now, http://example.com/s1/s2 will redirect to http://example.com/#/s1/s2
You can use mod_rewrite and javascript snippet in the client side to this task
Add the following to .htaccess
RewriteEngine On
RewriteBase /
RewriteRule "^([^?#].*)$" "/?$1" [R=301,NC]
Add following to main html
<script>
window.onload = function() {
location.hash = '/' + location.search.substr(1)
}
</script>
Now, http://example.com/s1/s2 will redirect to http://example.com/?s1/s2#/s1/s2
As your question states clearly you only need your html client routes to always have # right after domain name, here is a simple way to achieve it
As you are asking this for angular, so its very easy in that case. Just paste following code in element of index.html
<script>
var currentSitePageUrl = window.location.toString();
if(currentSitePageUrl.indexOf('#/') == -1)
{
window.location = currentSitePageUrl.replace(yourDomainUrl+'#/')
}
}
</script>
Above will include # to each url request and rest of the url will stay as it is, but only when it is requesting some front-end page
If you have access to .htaccess on your server, you can modify it to work with the URLs in your code without inserting the #.
There are really 2 parts to this, one enabling HTML5Mode in your Angularjs app and 2 editing the .htaccess file on your server to deal with this successfully.
I don't PHP at all, but was able to get this working for several sites following this article: https://ngmilk.rocks/2015/03/09/angularjs-html5-mode-or-pretty-urls-on-apache-using-htaccess/#thecode
try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} /(mypage2(/.*)|about-us) # you used mypage2, so it will be redirected to subsite/#/mypage2
RewriteRule ^(.+)$ /subsite/#/$1 [R=301,NC]
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/#/$1 [L,QSA]
notice the comment of the first rule.
and you can try your rules in sites like this: http://htaccess.mwl.be/
I tried this simple .htaccess redirect to remove the (.htm) extension from a single page.
Redirect 301 /mypage.htm http://www.mydomain.co.uk/mypage
However it returned a 404 page not found?
Dont use redirect, use mod-rewrite to rewrite your url.
Try :
RewriteEngine on
#1)redirect "/mypage.htm" to "/mypage"
RewriteCond %{THE_REQUEST} /mypage\.htm [NC]
RewriteRule ^ /mypage [NC,L,R]
#2)dont rewrite existing dirs and files
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
#3)rewrite "/mypage" to "/mypage.php"
RewriteRule ^mypage/?$ /mypage.htm [NC,L]