Redirect url that don't end with slash
-
Hi!
I need to add in my .htaccess a way to redirect URL that don't end with / to the one thats end wth /.For example, I need http://example.com to redirect to http://www.example.com/. And, of course, this redirection should be only for URLs that don't end with /, so I don't get double // at the end.
I already have the code to redirect the non-www to the www, but can't find a way to do the slash thing.
Thanks!
-
Thank you both!
-
do you have a number of URLS that you need to redirect ? or do you just want to redirect http://example.com to http://www.example.com/
This will add trailing slash to any URL
Add a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)$ $1/ [L,R=301] -
Hi Ariel,
I have found something on Stackoverflow: http://stackoverflow.com/questions/7780859/htaccess-rewrite-to-force-trailing-slash-at-the-end
Maybe you want to check it out, if it works for you.
Gr., Keszi
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
We just can't figure out the right anchor text to use
We have been trying everything we can with anchor text. We have read here that we should try naturalistic language. Our competitors who are above us in Google search results don't do any of this. They only use their names or a single term like "austin web design". Is what we are doing hurting our listings? We don't have any black hat links. Here's what we are doing now. We are going crazy trying to figure this out. We are afraid to do anything in fear it will damage our position. Bob | pallasart web design | 31 | 1,730 |
Technical SEO | | pallasart
| website by pallasart a texas web design company in austin | 15 | 1,526 |
| website by the austin design company pallasart | 14 | 1,525 |
| created by pallasart a web design company in austin texas | 13 | 1,528 |
| created by an austin web design company pallasart | 12 | 1,499 |
| website by pallasart web design an austin web design company | 12 | 1,389 |
| website by pallasart an austin web design company | 11 | 1,463 |
| pallasart austin web design | 9 | 2,717 |
| website created by pallasart a web design company in austin texas | 9 | 1,369 |
| website by pallasart | 8 | 910 |
| austin web design | 5 | 63 |
| pallasart website design austin |0 -
Duplicate title tags being caused by upper case and lower case version of urls'
Hi GWT is reporting lots of duplicate titles for a clients new site. Mainly these are due to 2x different versions of the url, one with words starting with an upper case character and the other all lower case. Clients dev saying this has something to do with windows server and is ok! Is this correct or should i be telling them to delete and then 301 redirect all upper case versions to the lower case (since lower case better practice) and that will deal with the reported dupe titles ? All Best Dan
Technical SEO | | Dan-Lawrence0 -
Should you use the canonicalization tag when the content isn't exactly a duplicate?
We have a site that pull data from different sources with unique urls onto a main page and we are thinking about using the canonicalization tag to keep those source pages from being indexed and to give any authority to the main page. But this isn’t really what canonicalization is supposed to be used for so I’m unsure of if this is the right move.
Technical SEO | | Fuel
To give some more detail: We manage a site that has pages for individual golf courses. On the golf course page in addition to other general information we have sections on that page that show “related articles” and “course reviews”.
We may only show 4 or 5 on each of those courses pages per page, but we have hundreds of related articles and reviews for each course. So below “related articles” on the course page we have a link to “see more articles” that would take the user to a new page that is simply a aggregate page that houses all the article or review content related to that course.
Since we would rather have the overall course page rank in SERPs rather than the page that lists these articles, we are considering canonicalizing the aggregate news page up to the course page.
But, as I said earlier, this isn’t really what the canonicalization tag is intended for so I’m hesitant.
Has anyone else run across something like this before? What do you think?0 -
Why are my URL's changing
My rankings suddenly dropped and when trying to understand why I realized that nearly all images in Google's cached version of my site were missing. In the actual site they appear but in the cached version they don't. I noticed that most of the images had a ?6b5830 at the end of the URL and these were the images that were not showing. I am hoping that I found the reason for the drop in rankings. Maybe since Google cannot see a lot of the content it decided not to rank it as well (particularly since it seems to happen on thousands of pages). This is a cached version of my site I am using the following plugins that might be causing it: Yoasts SEO plugin, W3 total cache. Does anyone know what is causing ?6b5830 to be added to the end of most of my URL's? Could this be the reason for the ranking drop? Thanks in advance!
Technical SEO | | JillB20130 -
Can't for the life of me figure out how this is possible !! Any ideas ?
I would imagine it's not all that easy to rank on 1st page ( not going for 1st position here ) for https://www.google.com.au/search?q=credi+cards. I am looking at the AU market. For some reason which I can't figure out Everyday Money Credit Card ( https://www.woolworthsmoney.com.au/ ) ranks number 4. The home page redirect to https://www.woolworthsmoney.com.au/wowm/wps/wcm/connect/wowmoney/wowmoney/home/home/ Why have your homepage in this format ? I would love to hear any theories you guys might have. It does not look like they have a strong link profile , I could not figure out how old the domain was or what other possible reason there is for the site to rank .
Technical SEO | | RuchirP0 -
OpenSite Explorer doesn't show Twitter
When I type competitors sites into opensiteexplorer it shows their Twitter page as one of the tops links back. However, my site, our Twitter page isn't even on the links back. Does twitter even though no follow hold any value? Why can't opensite explorer see it? If OSE can't see it then do you think Google isn't?
Technical SEO | | PhotoGazza0 -
Crawl reveals hundreds of urls with multiple urls in the url string
The latest crawl of my site revealed hundreds of duplicate page content and duplicate page title errors. When I looked it was from a large number of urls with urls appended to them at the end. For example: http://www.test-site.com/page1.html/page14.html or http://www.test-site.com/page4.html/page12.html/page16.html some of them go on for a hundred characters. I am totally stymied, as are the people at my ISP and the person who talked to me on the phone from SEOMoz. Does anyone know what's going on? Thanks So much for any help you can offer! Jean
Technical SEO | | JeanYates0 -
Is it better to delete web pages that I don't want anymore or should I 301 redirect all of the pages I delete to the homepage or another live page?
Is it better for SEO to delete web pages that I don't want anymore or should I 301 redirect all of the pages I delete to the homepage or another live page?
Technical SEO | | CustomOnlineMarketing0