Remove ?gclim=<random_code> using .htaccess - apache

I have this .htaccess
RewriteEngine On
Options -Indexes
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} !^www.****.com$
RewriteRule ^(.*)$ http://www.****.com/$1 [L,R=301]
RewriteCond $1 !^(index\.php|media|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
ErrorDocument 404 /page-not-found
And when google ads navigate to it because of the codeigniter setup it causes a 404, i need to remove the gclim from the URL completely.
How can i do that with pure .htaccess

I need to remove the gclim from the URL completely.
You can insert this redirect rule just below 2nd Options line:
ErrorDocument 404 /page-not-found
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*&)?gclim=[^&]*(?:&(.*))?$ [NC]
RewriteRule ^ %{REQUEST_URI}?%1%2 [L,R=301,NE]
RewriteCond %{HTTP_HOST} !^www.****.com$
RewriteRule ^(.*)$ http://www.****.com/$1 [L,R=301]
RewriteCond $1 !^(index\.php|media|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

Related

.htaccess file not working properly in ionos. My website- https://rentocure.com

I want to have clean link like- https://rentocure.com/doctors/rc635502e5e9376 instead of https://rentocure.com/doctors.php?uid=rc635502e5e9376 (U can go through my website). I have the following code in localhost
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)/$ $1 [L,R=301]
RewriteRule ^/?home/([^/]+)?$ "index.php" [L,QSA]
ErrorDocument 404 https://rentocure.com/404/
RewriteRule ^doctors/([^/]*)$ doctors.php?uid=$1 [L]
RewriteRule ^hospitals/([^/]*)$ hospitals.php?uid=$1 [L]
which is working fine in localhost but not in ionos apache server so I changed it to the following:
Options +MultiViews
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
#Redirect to SSL Secured Page
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(.*)$ https://rentocure.com/$1 [R=301,L]
#Removing File Extension .php and adding trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
#Custom 404 Page
ErrorDocument 404 https://rentocure.com/404/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^doctors/([^/]*)$ doctors/?uid=$1 [QSA,L]
But still it is not working kindly check my website and give me the solution. For the one whose solution will work for me will get assured cash reward from me.
Expecting solution through .htaccess code.

error 404 redirect not working with my .htaccess

I tried usingĀ 
ErrorDocument 404 /abc/404.php
But when the wrong URL is entered it redirects to the main page, not to the 404 error page
I have a htaccess file with this code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} /search(?:\.php)?\?search=([^\s&]+) [NC]
RewriteRule ^ search/%1? [R=302,L,NE]
RewriteRule ^search/(.*)/page/(.*)/?$ search.php?search=$1&page=$2 [NC,L]
RewriteRule ^search/(.*)$ search.php?search=$1 [L,QSA,NC]
RewriteRule ^category/(.*)/page/(.*)/?$ category.php?id=$1&page=$2 [NC,L]
RewriteRule ^category/(.*)$ category.php?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ viewpost.php?id=$1 [QSA,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
ErrorDocument 404 /abc/404.php
These two rules...
RewriteRule ^(.*)$ viewpost.php?id=$1 [QSA,L]
RewriteRule ^(.*)$ index.php/$1 [L]
Replace any URL that is accessed with the replacement... Unless the accessed URL is a real file/directory. As per the RewriteCond rules preceding them:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
If you don't want to divert every request that isn't a real file/directory then you need to change those rules...

htaccess fails to redirect when encounter whitespace

I am using htaccess for clean url. Which is working fine as long as the parameters doesn't carry whitespace. In which case it converts the space in %20 and I receive 404 error.
So basically the URL: http://localhost:8080/series/dynamics/admin/cleanURL/green%20apple
gives me 404 error. But URL: http://localhost:8080/series/dynamics/admin/cleanURL/greenapple works fine.
Also is there a way I can remove the directory details from the URL, I tried
RewriteRule ^series/dynamics/admin/cleanURL/(.*)$ /$1 [L,NC,R]
But doesn't work
htaccess
<IfModule mod_rewrite.c>
Options +MultiViews
Rewriteengine on
RewriteBase /series/dynamics/admin/cleanURL/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^series/dynamics/admin/cleanURL/(.*)$ /$1 [L,NC,R]
Rewriterule ^([a-zA-Z0-9]+)/?$ index.php?product=$1
RewriteRule ^(.*)(\s|%20)(.*)$ /$3-$4 [R=301,L,NE]
#rewrite group and subgroup e.g. http://.../value1/value2/ [L,NC,QSA]
Rewriterule ^([a-zA-Z0-9]+(.*)+)/([^/]+(.*)+)/?$ index.php?product=$1&subgroup=$2 [L,NC,QSA]
</IfModule>
You will need to add this rule in your site root .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) series/dynamics/admin/cleanURL/$1 [L]
Then have these rules in /series/dynamics/admin/cleanURL/.htaccess:
Options +MultiViews
Rewriteengine on
RewriteBase /series/dynamics/admin/cleanURL/
RewriteCond %{THE_REQUEST} /series/dynamics/admin/cleanURL/(\S*)\s [NC]
RewriteRule ^ /%1 [L,R=302,NE]
RewriteRule ^([^\s\x20]*)[\s\x20]+(.*)$ $1-$2 [L,R=302,NE]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
Rewriterule ^(\w+)/?$ index.php?product=$1 [L,QSA]
#rewrite group and subgroup e.g. http://.../value1/value2/ [L,NC,QSA]
Rewriterule ^([a-zA-Z0-9]+(.*))/([^/]+(.*))/?$ index.php?product=$1&subgroup=$2 [L,NC,QSA]

not getting slash / on my website url

My .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
#non www redirection
RewriteEngine On
RewriteCond %{HTTP_HOST} !^ruggedtrailsnepal\.com
RewriteRule (.*) http://ruggedtrailsnepal.com/$1 [R=301,L]
i am not getting / (slash) on some url , but some url's are working , how to solve this problem
link with problem
ruggedtrailsnepal.comtravel-info/visa-information.html
link without problem
ruggedtrailsnepal.com/company-info/about-us.html
Reorder your rules and use REQUEST_URI variable:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
#non www redirection
RewriteCond %{HTTP_HOST} !^ruggedtrailsnepal\.com$ [NC]
RewriteRule ^ http://ruggedtrailsnepal.com%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Better test this in a new browser to avoid old caches.

Make htaccess accept domain.com and www.domain.com

How to modify this htaccess so that it will allow www.domain.com and domain.com. Now when i give www.domain.com, it changes it to domain.com
Options -Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
RewriteRule ^$ website/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/website%{REQUEST_URI} -f
RewriteRule .* website/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* website/index.php?q=$0 [QSA]
Sorry, dont have much knowledge with htaccess
Just take out first 301 rules that strips www:
Options -Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^$ website/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/website%{REQUEST_URI} -f
RewriteRule .* website/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* website/index.php?q=$0 [L,QSA]