How to remove the slash at the end of the URL? - .htaccess

My problem is that when I visit my site I always see slash end of the url.
How do I disable that slash that's being added in .htaccess. Thanks!
www.example.com/products/type/name/

Related

Htaccess redirect only top level URL

I would like to redirect a top level page using htaccess, but not redirect tier pages. Let me explain. I currently have this redirect in place:
Redirect 301 /support /donate
In summary, I want someone to be redirected to /donate when the visit /support. However, with this rule if someone visits:
https://www.example.com/support/test
They are redirected to:
https://www.example.com/donate/test
I do NOT want them to be redirected in these instances - only if they visit /support or /support/ (note trailing slash).
I'm not sure how to do this or if this is possible. Any ideas?
The Redirect directive is prefix-matching, so you will need to use the RedirectMatch directive instead, which matches against a regex.
For example:
RedirectMatch 301 ^/support/?$ /donate
The above matches /support or /support/ only and redirects to /donate in both cases. Note that the previous Redirect directive would have redirected to /donate or /donate/ depending on whether there was a trailing slash on the initial request.
You will need to clear your browser cache before testing, since any erroneous 301 (permanent) redirects will have been cached persistently by the browser. Test first with 302s to avoid potential caching issues.
Reference:
https://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirect
https://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirectmatch

How to remove duplicate urls that are affecting my SEO

Hoping someone can help me. I've tried everything I can think of and have spent almost 2 weeks now trying to solve this issue. I'm using SERanking for a site audit and it is indicating I need to fix the duplicate url issue.
Pages With Issues:
https://www.droneworxphotography.com/
0 (Referring Pages)
https://www.droneworxphotography.com/index.html
10 (Referring Pages)
https://www.droneworxphotography.com
10 (Referring Pages)
My htaccess:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.droneworxphotography.com/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R] # <- for test, for prod use [L,R=301]
I've tried adding a 301 redirect, but it is not resolving my issue.
Redirect 301 /droneworxphotography.com/index.html /droneworxphotography.com
I'm hoping someone can help me with fixing this.
Thanks
As mentioned in comments, you need to actually fix your internal links so you are consistently linking to the canonical URL throughout your site, before attempting to implement redirects.
The "reported issues" you are seeing are presumably discovered by crawling your site.
As far as I can tell, my internal links are consistent.
Unfortunately not...
<!--begin footer_details -->
<ul class="footer_details">
<li>
<li> Redacted Photography
(Ignoring the incorrectly nested li elements - this is not valid HTML.)
You have a relative link to index.html in the footer of every page. This should be either, a root-relative URL (a single slash):
Redacted Photopgraphy
Or, an absolute URL (include the scheme + canonical hostname). For example:
Redacted Photopgraphy
Note the trailing slash after the hostname.
These two are the same. (Providing the hostname is correctly canonicalised before reaching your site. It appears to be - you have HTTP to HTTPS and non-www to www redirects in place.)
<!--begin logo -->
<img src="lib/images/cropped-DroneworxLogo_small.png" alt="Logo">
<!--end logo -->
<!--begin nav -->
<ul id="nav">
<li>
<i class="icon-home"></i><br>Home
You have 3 links on every page (the two above and one in the footer - copyright link) that links to scheme + hostname but without the trailing slash.
Strictly speaking, the "correct" URL includes the trailing slash after the hostname.
User-agents (ie. browsers) will correct this and always append the trailing slash, but you should be consistent and link to href="https://www.example.com/" - with a trailing slash. (Or use href="/" as mentioned above.)
Your XML sitemap already correctly links to the canonical absolute URL (with a trailing slash): <loc>https://www.example.com/</loc>
It is this inconsitency that is causing the SEO tool to report on both https://www.example.com/ (slash) and https://www.example.com (no slash). Although this is not really an SEO issue, since user-agents will always append the trailing slash to form a valid URL, as mentioned above. See my answer to the following question on the Webmasters Stack for more information about the trailing slash after the hostname: Is trailing slash automagically added on click of home page URL in browser?
Note that the trailing slash immediately after the hostname (at the start of the URL-path) is not the same thing as the trailing slash at the end of the URL-path.
Redirect to canonical
Once you have corrected the above then you can implement a redirect to correct any indexed URLs (or backlinks from external third parties).
The only redirect you could implement here is from /index.html to / (to remove index.html). You cannot redirect to append a trailing slash after the hostname (this is the same URL).
(Your mod_rewrite directives remove the trailing slash at the end of the URL-path - which is something different entirely. Your site does not have an issue with this, but this redirect causes no harm.)
To remove index.html you could add the following rule at the top of the .htaccess file, before your existing redirects (and after the RewriteEngine directive):
RewriteRule ^index\.html$ https://www.example.com/ [R=301,L]
NB: Test first with a 302 (temporary) redirect to avoid potential caching issues.
This does assume you aren't using a front-controller pattern (and rewriting requests to /index.html). It doesn't look like you are - your site looks like an entirely static HTML site?
A quick check in Google using a site: search does not show that index.html has been indexed. So, this was unlikely causing you an SEO issue at the current time.

How to add trailingshlash to redirect IF NOT already there in .htaccess (while pointing to new domain)

I migrated to a new domain so I would like all old url's point to the exact same page on the new url. Therefore I only have this code in my .htaccess file and this is doing what I would like it to do:
RewriteEngine on Redirect 301 / https://meditatieinstituut.nl/
But some old links with value does not have a trailing slash and the redirect to the trailing slash will only be made on the new domain. Therefore there is 1 more redirect than neccessary.
For example check this url in httpstatus.io:
http://www.vihara.nl/bewustwording/hoe-moet-je-mediteren-uitleg-vipassana-meditatie
So I would like:
http://www.vihara.nl/bewustwording/hoe-moet-je-mediteren-uitleg-vipassana-meditatie
NOT TO REDIRECT FIRST TO:
http://www.meditatieinstituut.nl/bewustwording/hoe-moet-je-mediteren-uitleg-vipassana-meditatie
BUT DIRECTLY TO:
http://www.meditatieinstituut.nl/bewustwording/hoe-moet-je-mediteren-uitleg-vipassana-meditatie/
So to redirect to the new domain WITH already with the trailing at the end.
But this should only be done if there is no trailingslash at the end.
Does anyone know how to do this?

Remove special word from end of URLs with htaccess?

Google has founded 7500 Not Found 404 Error and I found out that almost all of them happened because of a button with "YourDrible" in href (only this word in url field) and all pages has this button so there are 7 k pages with this url pattern:
http://Some-True-URL/YourDribble
is there any way that I can put in htaccess or somewhere tell that every URL with "/YourDribble" at end should redirect to URL without this word at end?
Thank you for your time
In your .htaccess file:
RewriteEngine on
RewriteRule ^(.*)/YourDribble$ http://Some-True-URL/$1 [R=301,L]

How Adding slash into rewrite rules href link

i am using the rewrite rules in htaccess but i am getting error on site,
while adding a / (slash) into the link
My Example Code:
RewriteEngine On
RewriteRule ^categories/(.*)$ ?act=directory&category=$1 [L]
actually i want to call this link from the category listing where the href link is
categories/category-name
now if i call this link like this
categories-category-name
then it works fine, but if i add the slash then the site looks as it doesnt have the css :(
only unstyled text i can see.
Thanks In Advance
Please Advise.
You need to add a slash in your css path
href="/css/your_style_name.css"
This will work

Resources