Google Search Index, Access Denied 403 error html website - .htaccess

My website is html based (https://shivit.com) and all pages opening fine on browser but in google search console showing home page not indexed due to Failed: Blocked due to access forbidden (403)
I have tried everything in htaccess file also but nothing worked, my current htaccess file look like:
Please suggest what changes i should do to index home page and remove too many redirects.
RewriteOptions inherit
# < IfModule mod_rewrite.c >
#RewriteEngine On
#RewriteBase /
#RewriteRule ^ index.html$ - [L]
#RewriteCond % {
REQUEST_FILENAME
}!-f
#RewriteCond % {
REQUEST_FILENAME
}!-d
#RewriteRule.index.html[L]
# < /IfModule> <
IfModule mod_rewrite.c >
RewriteEngine On
#RewriteRule ^ index.html$ - [L]
RewriteCond % {
REQUEST_FILENAME
}!-f
RewriteCond % {
REQUEST_FILENAME
}!-d
RewriteRule.index.html[L]
RewriteCond % {
HTTP_HOST
} ^ www\.(.*) $[NC]
RewriteRule ^ (.*) $ https: //%1/$1 [R=301,L]
<
/IfModule>
#RewriteEngine On
#RewriteCond % {
HTTP_HOST
} ^ shivit\.com[NC]
#RewriteCond % {
SERVER_PORT
}
80
#RewriteRule ^ (.*) $ https: //shivit.com/$1 [R,L]
RewriteEngine On
RewriteCond % {
SERVER_PORT
}
80
RewriteRule ^ (.*) $ https: //shivit.com/$1 [R,L]
Options - Indexes
I have tried to modify htaccess file and index request to google but nothing worked.

Related

Rewrite url name using with .htaccess

I have sample website name is example.com/customer/?loc=dashboard, this website is used PHP coding. I need to change last name ?loc=dashboard to dashboard. That means I want the result website name is mydomain.com/customer/dashboard
I have added a file called .htaccess in my root folder, and add something like this, but it cannot work:
ReWriteEngine On
RewriteRule ^/dashboard /?loc=dashboard [L]
I have refer this website https://mediatemple.net/community/products/dv/204643270/.htaccess-rewrite-rules to do. But cannot work. Hope someone can guide me on how to solve this problem. Thanks.
Updated - 1
Using #RavinderSingh13 method result:
Before ?loc=dashboard result:
Updated 12/11/2021 09:19:00
Rewrite rules
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com\.my [OR,NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com.my/$1 [R,L]
RewriteCond %{HTTP_HOST} ^example\.com\.my [OR,NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mydomain.com.my/$1 [R,L]
##External redirect to /customer/dashboard url rules here.
RewriteCond %{THE_REQUEST} \s/customer/?\?loc=(\S+)\s [NC]
RewriteRule ^ /customer/%1? [R=301,L]
##Internal rewrite rules to get it served by index.php file.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^customer/(.*)/?$ index.php?parameter=$1 [QSA,NC,L]
Update - 2
everyoneknows.come.my/.htaccess
everyoneknows.come.my/index.php
everyoneknows.come.my/customer
everyoneknows.come.my/customer/index.php
everyoneknows.come.my/customer/account/dashboard.php
So that, in my php code, I use ?loc= replace account, then become everyoneknows.come.my/customer/?loc=dashboard
Update -3
I am using this method to get ?loc:
if (isset($_GET['loc'])) {
if (file_exists('account/' . $_GET['loc'] . '.php')) {
// if ($module_user_permission['view'] == 1) {
include_once 'account/' . $_GET['loc'] . '.php';
// } else {
// if ($_GET['loc'] != 'home') {
// include_once 'app/access_denied.php';
// } else {
// include_once 'account/dashboard.php';
// }
// }
} else {
include_once 'account/dashboard.php';
}
} else {
include_once 'account/dashboard' . (isset($_GET['system']) ? "_" . $_GET['system'] : "") . '.php';
}
With your shown attempts, samples; please try following htaccess rules file. Please make sure to clear your browser cache before testing your URLs.
Make sure your htaccess rules file is present alongside with customer folder(not inside it). In 2nd rewrite rule I have added parameter to get it pass to index.php file you can set it as per your requirement.
RewriteEngine ON
##Applying www by external redirect rules here...
RewriteCond %{HTTP_HOST} ^example\.com\.my [NC]
RewriteCond HTTPS off
RewriteRule ^(.*)/?$ https://www.example.com.my/$1 [R,L]
##External redirect to /customer/dashboard url rules here.
RewriteCond %{THE_REQUEST} \s/customer/?\?loc=(\S+)\s [NC]
RewriteRule ^ /customer/%1? [R=301,L]
##Internal rewrite rules to get it served by dashboard.php file.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^customer/(.*)/?$ customer/account/dashboard.php?parameter=$1 [QSA,NC,L]

Redirect Old IDX home listing pages to Search Page

We are getting a lot of 404 errors on a Real Estate website after houses are sold and the listing goes offline. I am trying, via htaccess, to redirect the missing pages that Google Search Console shows as 404 to a home listing search page. I have tried the code below but it is redirecting all listing pages not just the ones that no longer exist. Not sure if it's my code or because the pages are dynamically created.
All the home listings are under www.example.com/homes-for-sale-details/[address]. If the listing no longer exists I want the page to redirect to www.example.com/homes-for-sale-details.
My htaccess code
# Redirect old home listing to a search page
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^homes-for-sale-details/(.*)$ https://www.example.com/homes-for-sale-details [L,NC,R=301]
</IfModule>
Where are I going wrong?
Many Thanks!
Edit (added more of htaccess code):
####################################
# START Redirect pages from old site
#
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^Properties https://www.example.com/home-listings [L,NC,NE,R=301]
RewriteRule ^Access https://www.example.com/search-homes [L,NC,NE,R=301]
RewriteRule ^Neighboorhoods https://www.example.com/neighborhoods [L,NC,NE,R=301]
RewriteRule ^Buyer-Resources https://www.example.com/buy-home-in-colorado-springs [L,NC,NE,R=301]
RewriteRule ^Relocation-Guide https://www.example.com/buy-home-in-colorado-springs/relocation-guide [L,NC,NE,R=301]
RewriteRule ^Buyer-Resources/Buyer-Finance/Finance-Information https://www.example.com/buy-home-in-colorado-springs/home-finance [L,NC,NE,R=301]
RewriteRule ^Seller-Resources https://www.example.com/sell-colorado-springs-home [L,NC,NE,R=301]
RewriteRule ^Area-Schools https://www.example.com/local-lifestyle/area-schools [L,NC,NE,R=301]
RewriteRule ^Colorado-Springs-Attractions https://www.example.com/local-lifestyle/colorado-springs-attractions [L,NC,NE,R=301]
RewriteRule ^Military-Bases https://www.example.com/local-lifestyle/military-bases [L,NC,NE,R=301]
RewriteRule ^About$ https://www.example.com/about-us [L,NC,NE,R=301]
RewriteRule ^contact$ https://www.example.com/contact-us [L,NC,NE,R=301]
RewriteRule ^Terms-Of-Service https://www.example.com/terms-of-service [L,NE,R=301]
RewriteRule ^Privacy-Policy https://www.example.com/privacy-policy [L,NE,R=301]
RewriteRule ^Site-Map https://www.example.com/sitemap [L,NC,NE,R=301]
RewriteRule ^neighborhoods/fountain$ https://www.example.com/neighborhoods/fountain-security-widefield [L,NC,NE,R=301]
RewriteRule ^neighborhoods/securitywidefield https://www.example.com/neighborhoods/fountain-security-widefield [L,NC,NE,R=301]
RewriteRule ^park-avenue-properties-blog https://www.example.com/blog [L,NC,NE,R=301]
RewriteRule ^Primary-Factors-the-Affect-the-Real-Estate-Market https://www.example.com/primary-factors-affect-real-estate-market [L,NC,NE,R=301]
</IfModule>
# END Redirect pages from old site
# Force HTTPS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
</IfModule>
# Remove "Blog" from blog post URLs and preserve blog paging
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !page
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^Blog/(.*)$ /$1 [L,NC,R=301]
</IfModule>
# Redirect old home listing to a search page
#<IfModule mod_rewrite.c>
# RewriteEngine On
# RewriteBase /
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteRule ^homes-for-sale-details/(.*)$ https://www.example.com/homes-for-sale-details [L,NC,R=301]
#</IfModule>
####################################
# Browser caching code removed :)
####################################
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I've tried to get this to work with the .htaccess file and could not. The issue with your script above is that you're not checking first for the 404 error, so all requests from that "folder" are being redirected. I've tried using the ErrorDocument directive in the .htaccess file with no luck, so the solution I worked out was to just use what wordpress already provides. In your themes subfolder (/wp-content/themes/THEMENAME) there should be a 404.php file. If it's not there you can create it. You can use some code at the top of this file to parse the request url and redirect the page. Something like this should work:
<?php
if (strpos($_SERVER['REQUEST_URI'], 'homes-for-sale-details') !== false)
header('Location: /homes-for-sale-details', true, 301);
else {
?>
// ... paste the current 404.php content here
<?php } ?>
Just remember to back up your current 404.php page in case you overwrite something you didn't mean to. If you want to try to get this working with the ErrorDocument stuff in htaccess be my guest, but for whatever reason, it wasn't working for me. Here's a post that shows how to do that.
Good luck!
After unsuccessfully trying to find a htaccess answer slim's answer got me thinging and I found this post WordPress Template Redirect (thank you so much for your help slim!!!)
Here is the modification I made to that code.
// Redirect missing home listing to a search page.
function __404_template_redirect()
{
if( is_404() )
{
$req = $_SERVER['REQUEST_URI'];
if ( is_file( $req )) {
return; // don't reduce perf by redirecting files
}
// check if "homes-for-sale-details" is in the URL
if ( strpos($req, 'homes-for-sale-details') == false ) {
return; // only redirect missing homes
}
// pull the parent directory and convert to site url
$parent_url = get_permalink( 1232 );
// redirect to parent directory
wp_redirect( $parent_url, 301 );
exit();
}
}
add_action( 'template_redirect', '__404_template_redirect' );

Error installing another PHP app in subfolder of SilverStripe

I have Silverstripe installed on www.mywebsite.com (I made that up just as an example)
I am testing Wordpress on www.mywebsite.com/test
Here is my .htaccess file in my root folder:
### SILVERSTRIPE START ###
# Deny access to templates (but allow from localhost)
< Files *.ss >
Order deny,allow<br>
Deny from all<br>
Allow from 127.0.0.1
< /Files >
# Deny access to IIS configuration
< Files web.config >
Order deny,allow
Deny from all
< /Files >
# Deny access to YAML configuration files which might include sensitive information
< Files ~ "\.ya?ml$">
Order allow,deny
Deny from all
< /Files>
# Route errors to static pages automatically generated by SilverStripe
ErrorDocument 404 /assets/error-404.html
ErrorDocument 500 /assets/error-500.html
< IfModule mod_env.c>
# Ensure that X-Forwarded-Host is only allowed to determine the request
# hostname for servers ips defined by SS_TRUSTED_PROXY_IPS in your _ss_environment.php
# Note that in a future release this setting will be always on.
SetEnv BlockUntrustedIPs true
< /IfModule>
< IfModule mod_rewrite.c>
# Turn off index.php handling requests to the homepage fixes issue in apache >=2.4
< IfModule mod_dir.c>
DirectoryIndex disabled
< /IfModule>
SetEnv HTTP_MOD_REWRITE On
RewriteEngine Off
# Enable HTTP Basic authentication workaround for PHP running in CGI mode
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Deny access to potentially sensitive files and folders
RewriteRule ^vendor(/|$) - [F,L,NC]
RewriteRule silverstripe-cache(/|$) - [F,L,NC]
RewriteRule composer\.(json|lock) - [F,L,NC]
# Process through SilverStripe if no file with the requested name exists.
# Pass through the original path as a query parameter, and retain the existing parameters.
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* framework/main.php?url=%1 [QSA]
# If framework isn't in a subdirectory, rewrite to installer
RewriteCond %{REQUEST_URI} ^(.*)/framework/main.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . %1/install.php? [R,L]
< /IfModule><br>
### SILVERSTRIPE END ###
< IfModule pagespeed_module>
ModPagespeed Off
</IfModule>
< IfModule mod_expires.c><br>
ExpiresActive Off<br>
< /IfModule>
Code on /test/.htaccess:
< IfModule mod_rewrite.c><br>
SetEnv HTTP_MOD_REWRITE On<br>
RewriteEngine On<br>
RewriteBase /<br>
RewriteCond %{REQUEST_URI} !/test<br>
RewriteEngine On<br>
RewriteCond %{REQUEST_FILENAME} !-f<br>
RewriteCond %{REQUEST_FILENAME} !-d<br>
RewriteRule . /index.php [L]<br>
< /IfModule>
Any ideas? Note: The < br > does not show up in the actual file and there are no spaces between the < and >
I get a list of all my files. My index.php file doesn't even show up properly and the URL changes from /test to test/?url=/test
I use zoom.ph shared hosting.
Update:
My new code in the root .htacccess file:
RewriteEngine On
# Change any direct URLs (www.unclebubby.com...) to the subdomain (wavs.unclebubby.com)
RewriteCond %{HTTP_HOST} ^(www\.)?collegeconnect\.ph$ [NC]
RewriteCond %{REQUEST_URI} ^/test/(.*)$ [NC]
RewriteRule .* http://test.collegeconnect.ph/%1 [R=301,L]
RewriteCond %{REQUEST_URI} !/test
# If there is a .htm at the end of the URL, get rid of it (due to migration of site from FrontPage)
RewriteCond %{REQUEST_URI} ^/(.+)\.htm$ [NC]
RewriteRule ^.+\.htm$ /%1 [R=301,L]
RewriteBase /
### SILVERSTRIPE START ###
I tested this and what you have seems to work fine. Just ensure you have no errors in your htaccess. You can check apache.log for this.
Here's what I used:
DirectoryIndex index.html index.php
<IfModule mod_rewrite.c>
SetEnv HTTP_MOD_REWRITE On
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/test
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
This redirected me successfully to the Wordpress setup page (fresh install).
First, your RewriteBase in test/.htaccess is wrong. It's not "/" (root), but "/test/" (as files are there).
Second, you have "RewriteEngine On" twice in your test/.htaccess - which may not be an error, but not needed anyway.
Third - your test/.htaccess file is literally disabled by itself by line:
RewriteCond %{REQUEST_URI} !/test
which means - all requests that don't have "test" in URL, which no request to "test" folder can fullfil. Your test/.htaccess should look like this:
< IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
< /IfModule>
BONUS: Silverstripe scans entire folder where it is installed and adds those classes to its manifest, which means you should exclude wordpress (ie folder "test") by placing empty file called "_manifest_exclude" in it.
mention folder name in 'RewriteBase' like below in .htaccess file at your root path
RewriteBase '/SilverStripe/'
where SilverStripe be ur folder name like u mentioned
RewriteBase '/test/'
please do remember to add slash before and after the folder name. If it doesnt work , then let me know. Thanks

Absolute path in RewriteRule

My link which need to be rewrited :
http://www.example.com/uploads/lu/full/00bcde2d484f1dab979c19f14b2f38bfabf13496_152_152.jpg
My rule
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)_([0-9]+)_([0-9]+)\.(jpg|jpeg|png|gif)$ http://test.mywebsite.com/themes/publisher/vignettes/resize.php?src=$1.$4&h=$2&w=$3
Output url
http://test.mywebsite.com/themes/publisher/vignettes/resize.php?src=uploads/lu/full/00bcde2d484f1dab979c19f14b2f38bfabf13496.jpg&h=152&w=152
Expected url
http://test.mywebsite.com/themes/publisher/vignettes/resize.php?src=http://www.example.com/uploads/lu/full/00bcde2d484f1dab979c19f14b2f38bfabf13496.jpg&h=152&w=152
http://www.example.com is not on my output url and i don't understand why
You need to capture values from %{REQUEST_URI that always contains full path:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^(.*)/([^/]*?)_([0-9]+)_([0-9]+)\.(jpe?g|png|gif)$ [NC]
RewriteRule ^ http://test.mywebsite.com/themes/publisher/vignettes/resize.php?src=http://%{HTTP_HOST}%1/%2.%5&h=%3&w=%4 [L,NE,R=302]

.htaccess to nginx rewrite rules excluding certain folders

So im trying to move an application from apache to NginX but I've discovered i need to re write the .htaccess file, I've had a good look around but finally I need to ask for some help.
Below is the .htaccess file from apache, im trying to redirect all requests to index.php except for requests to /html, /css, /images, /php.
Thanks for your help in advance!
Bill
RewriteEngine on
RewriteRule ^html [L,NC]
RewriteRule ^css [L,NC]
RewriteRule ^images [L,NC]
RewriteRule ^php [L,NC]
RewriteRule ^.*$ index.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !directory/(.*)$
RewriteCond %{REQUEST_URI} !(.*)$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
So far I have the below and the requests for the html, css, images and php files are working great.
But when i make a request for www.domain.com/blah/blah/blah/ im getting a 404, what i really want is for the URL to reamin as www.domain.com/blah/blah/blah/ but load the index.php file
location ~ directory/(.*)$ {
}
location ~ (.*)$ {
}
location /html {
rewrite ^/html / break;
}
location /css {
rewrite ^/css / break;
}
location /images {
rewrite ^/images / break;
}
location /php {
rewrite ^/php / break;
}
location / {
rewrite ^(.*)$ /index.php break;
if (!-e $request_filename){
rewrite ^(.*)$ http://www.domain.com/$1 redirect;
}
}
Try something along these lines for filtering requests to content in specific folders:
RewriteEngine On
# if not requesting content in one of the specified folders
RewriteCond %{REQUEST_FILENAME} !^(html|css|images|php)/ [NC]
# redirect visitor to the index page
RewriteRule ^(.*)$ index.php [L,QSA]
The exclamation mark ( ! ) before the rewrite condition means a negation, so if the requested filename DOES NOT start with html or css or ...., apply the rewrite rule.

Resources