Set 410 list of url with space - .htaccess

I have list of url with space on it , And i want to set them as gone (410)
https://www.website.com/Enhanced Category/religions/page/28
https://www.website.com/Enhanced Category/
Im on shared hosting using litespeed server...tried to encode the space on my htaccess
https://www.website.com/Enhanced%20Category/religions/page/28
https://www.website.com/Enhanced%20Category/
but it failed, the url still serve as 404...can anyone help me?
My htaccess
RewriteEngine On
Redirect 410 /Enhanced%20Category
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
RewriteRule ^\d{4}/\d\d/([\w-]+\.html)$ /$1 [R=301,L]
<Files xmlrpc.php>
Order Allow,Deny
Deny from all
</Files>
Options All -Indexes
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Requested url
https://www.website.com/Enhanced Category return 404 status
https://www.website.com/Enhanced%20Category return 410 status

Based on your shown samples, could you please try following. Please make sure you clear your browser cache before testing your URLs, fair warning haven't tested full htaccess file since there are other rules mentioned by OP with my added ones.
<Files xmlrpc.php>
Order Allow,Deny
Deny from all
</Files>
<IfModule mod_rewrite.c>
RewriteEngine ON
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
RewriteRule ^\d{4}/\d\d/([\w-]+\.html)$ /$1 [R=301,NE,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^Enhanced%20Category/religions/page/28/?$ - [R=401,L]
RewriteRule ^Enhanced Category/?$ - [R=401,L]
</IfModule>

Related

redirect http to https making a problem in subdirectory as 404 - Not found

htaccess in root folder
#<IfModule mod_rewrite.c>
#RewriteEngine On
#Uncomment these two lines If you want to redirect http to https
#RewriteCond %{HTTPS} off
#RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ index.php [L]
#</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^https://3pmix.com/ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
htaccess in sub folder
RewriteRule ^classes/.*$ - [F,L]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_URI} config.php|db.php|functions.php [NC]
RewriteRule .* - [F,L]
directory structure through images
With your shown samples, please try following Rules file. Also make sure to clear your browser cache before testing your URLs.
Have your root htaccess Rule file like as follows:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^3pmix\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
</IfModule>
And have your sub directory htaccess Rules file as follows:
RewriteOptions InheritBefore
RewriteEngine ON
RewriteRule ^classes - [NC,F,L]
RewriteRule (?:config\.php|db\.php|functions\.php) - [NC,F,L]
I have also fixed flags and regex in your htaccess files.
Rewrite base was missing that is why was not finding the root url of the website
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>

.htaccess redirect conflict with other code in file?

I am trying to alter my .htaccess file so when URL https://www.metaalboutique.nl/Contactformulier is used page https://www.metaalboutique.nl/contact_form.php is shown.
Is there some code in my .htaccess file that is conflicting with this and that might be the reason that this is not working?
<Files .htaccess>
order allow,deny
deny from all
</Files>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
ErrorDocument 404 /index.php
RewriteCond %{HTTP_HOST} !^www.metaalboutique.nl$
RewriteRule ^(.*)$ https://www.metaalboutique.nl/$1 [R=301,L]
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^metaalboutique\.nl$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.php [NC,L]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Redirect 301 /closed/index.php https://www.metaalboutique.nl
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?metaalboutique.nl [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
RewriteRule ^Contactformulier$ contact_form.php
Your Rule RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.php [NC,L] rewrites everything that is not a directory to php . This also matches /Contactformulier and rewrites it to /Contactformulier.php . You can either remove this rule from your htaccess or use the following modified version of your htaccess .
<Files .htaccess>
order allow,deny
deny from all
</Files>
Redirect 301 /closed/index.php https://www.metaalboutique.nl/
RewriteEngine on
#redirect http to https and non-www in a single redirect
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^metaalboutique.nl$ [NC]
RewriteRule (.*) https://www.metaalboutique.nl/$1 [R=301,L]
#deny access to remote referers
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?metaalboutique.nl [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
#access .php files without using extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
#rewrite /Contactformulier to /contact_form.php
RewriteRule ^Contactformulier$ contact_form.php [L]
Make sure to clear your browser cache before testing this .

.htaccess redirect to HTTPS doesn't work correctly

Redirect works only on the first page, http://example.com to https://example.com.
But it doesn't work on subfolders: http://example.com/news or /news/category etc. redirects me to the https://example.com/index.php (My website is on Laravel 5.5).
Any suggestions pls?
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
# ensure !www.
RewriteCond %{HTTP_HOST} ^www\.(.*)$
RewriteRule ^(.*)$ https://%1/$1 [L,R=301]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Header add Access-Control-Allow-Origin "http://glyphicons.com/"
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
Remember to replace example.com and www.example.com with your actual domain name

Redirect Page in Subfolder To New Folder

All of these redirects work except the pages located in sub directories for example:
fr/stuff
to
fr/other-stuff
does not work
RewriteEngine On
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^/?stuff$ http://example.org/more-stuff [R=301,L]
RewriteRule ^/?fr/stuff$ http://example.org/fr/other-stuff [R=301,L]
RewriteRule ^/?es/notice\.php$ http://example.org/es/ [R=301,L,QSD]
RewriteRule ^/?len.php$ http://example.org/es/ [R=301,L,QSD]
this is the rest of the code
# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php
RewriteEngine On
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \.htm
RewriteRule ^(.*)\.htm$ /$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.htm -f
RewriteRule ^([A-Za-z\-]+)$ $1.htm
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^\.localhost$ [NC]
RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/$1 [R=301,L]
<FILES .htaccess>
order allow,deny
deny from all
</FILES>
/fr/stuff will redirect correctly to /fr/stuff
but /fr/stuff/ and other content in the directory will not redirect.
To redirect /fr/stuff/ you should do like this
RewriteRule ^/?fr/stuff/?$ http://example.org/fr/other-stuff [R=301,L]
To redirect the subdirectory do like this
RewriteRule ^/?fr/stuff/?(.*)$ http://example.org/fr/other-stuff/$1 [R=301,L]
You should read more about regular expression for details.

Htaccess RewriteRule change subdomain url

I'm in this situation
http://example.com/sub-domain/
and I wish to have this
http://example.com/sub/domain/
without loosing in SEO, what's the right RewriteRule?
At the moment this is my .htaccess file in the subdomain DOCUMENT_ROOT
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /sub-domain/
# exclude any paths that are not codeigniter-app related
RewriteCond %{REQUEST_URI} !^/server-status
RewriteCond %{REQUEST_URI} !^/server-info
RewriteCond %{REQUEST_URI} !^/docs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
# the following is for rewritting under FastCGI
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
EDIT
In my root domain I have installed Wordpress and this is the .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [QSA,L]
</IfModule>
Leave /sub-domain/.htaccess as is. And have this rule in root .htaccess (a level above /sub-domain/):
RewriteEngine On
RewriteCond %{THE_REQUEST} /sub-domain(\S*)\s [NC]
RewriteRule ^ /sub/domain%1? [R=301,L,NE]
RewriteRule ^sub/domain(/.*)?$ sub-domain$1 [L,NC]

Resources