My URL
myurl.co.kr
Redirected URL
myurl.co.kr/#page1
I have tried this code:
RewriteCond %{REQUEST_URI}
RewriteRule ^(.*)$ ./index.php/#page1
However, this caused "too many redirections" on chrome.
How should I change the .htaccess file so that it redirects with the "/#page1" added on the URL?
Related
I discovered recently that a Hostgator tech inserted rewrite code in my .htaccess file which 302 redirected all of my pages to https://example.com even though I wasn't using that URL path for my sitemap or internal links. Now I have a mix of URL paths indexed by Google and lots of duplicate pages.
Trying to clean it up and use one URL path -> https://example.com
This is the code they inserted:
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
RewriteEngine on
RewriteOptions inherit
Can I simply change the [R,L] to [R=301,L] so that now everything will be a permanent redirect? I will also update all internal links and sitemap to use this URL path.
Try to set 404 page not found error page by htaccess.
Issue is if we are searching for
https://www.rsseosolution.com/suraj.html ... Its redirect perfect to 404.php.
But if we are searching for
https://www.rsseosolution.com/suraj.php ... Its not redirecting to 404.php and giving showing simple text message "File not found.".
In short problem is if extension is not php then its redirecting fine but if .php then its showing File not found.
ErrorDocument 404 https://www.rsseosolution.com/404.php
Options +FollowSymLinks
RewriteEngine on
# ensure www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule seo-package-(.*)-n-(.*)\.php$ seo-package-detail.php?id=$1&name=$2 [NC,L]
RewriteRule case-studies/(.*)-(.*)\.php$ case-studies.php?project=$1&id=$2 [NC,L]
RewriteRule tutorial/(.*)-(.*)\.php$ tutorial.php?topic=$1&id=$2 [NC,L]
RewriteRule blog-page-(.*)\.php$ blog.php?page=$1 [NC,L]
RewriteRule seo-tutorial-(.*)\.php$ seo-tutorial.php?page=$1 [NC,L]
RewriteRule frequently-ask-question-faq-(.*)\.php$ frequently-ask-question-faq.php?page=$1 [NC,L]
What i am looking for is ....... redirect all not found or wrong URL to 404.php.
What i am missing here.
I think because we are rewriting some URLs with .php extension from htaccess and thats why for PHP its saying file not found but for other its redirecting perfectly to 404.php.
Is there any ways to set 404.php for all not found pages and URL without change any extension (.php) of previous written file by htaccess.
The problem is not to do with your current directives in .htaccess.
The problem is mostly likely due to your server config and the way PHP is implemented on your server. If requests for .php files are proxied to a backend server for processing as is often the case with FastCGI type configs then this 404 Not Found message is likely coming from the backend server and not your Apache server.
Ordinarily, you would solve this with the ProxyErrorOverride directive in the reverse proxy config:
ProxyErrorOverride On
If you don't have access to the main server config then you may be able to trigger the 404 early using mod_rewrite in .htaccess, before the request is sent to the proxy server.
For example, before your existing mod_rewrite directives:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.php$ - [R=404]
However, this is strictly a "workaround", if you have access to the server config then using ProxyErrorOverride (as mentioned above) is preferable.
Aside:
ErrorDocument 404 https://www.rsseosolution.com/404.php
By specifying an absolute URL in the ErrorDocument directive this triggers an external (302) redirect for the error document (an additional request), which is generally undesirable (and you need to manually set the 404 response code). It is far better to issue the error document as an internal subrequest instead:
ErrorDocument 404 /404.php
I want my domain, theatrenearyou.org, to automatically redirect to www.theatrenearyou.org. I have a .htaccess file in my site's root directory along with some html files, but when I visit https://theatrenearyou.org it does not redirect to https://www.theatrenearyou.org
I'm using InMotionHosting, and I've made sure my .htaccess file is being read by testing out some redirects such as redirecting /pizza to /about.html. It seems like the .htaccess file is being read, but for some reason no matter what I do I cannot get it to force www.
This is what I currently have in my .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
This should redirect to https://www.theatrenearyou.org but instead the URL remains at https://theatrenearyou.org.
For some odd reason when I visit my site without the "www." it redirects properly. However when I try to visit mywebsite.com/test.php it will redirect to mywebsite.com/public_html/test.php.
For some odd reason it adds "public_html" to the redirect breaking the page
My .htaccess is on the same level as the public_html place. Below is the code im using in the .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mywebsite\.com [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301,NC]
I have a website hosted on a free web hosting
it really messed my mind i put two codes in htaccess file one for 404 redirection
and other is for removing .html extension
in google chrome only one file is getting redirected on index.html [ i have total three.html files]
and in firefox no file is getting redirected its showing error and getting redirected on hosting website
when i put www.example.com/hello
it works fine
but when i put www.example.com/hello.html
it does not redirect on index page
same happens with if i type incorrect words it does not redirect on index.html
and when i remove second code (html extension remover) so 404 redirect code works fine
why?? what is the reason? is it not possible to add to 2 codes togather in htaccess file?
here is the code of htaccess--
# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteBase /
ErrorDocument 404 /index.html
RewriteEngine on
RewriteBase /
RewriteCond %{http://www.example.com/new} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) /$1.html [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP
RewriteRule ^([^.]+)\.html$ http://www.example.com/new/$1 [R=301,L]