1 min read

Add Trailing Slash to URLs in Drupal 7

To add a trailing slash to URLs on every Drupal page, you can use the Trailing Slash module, which handles this automatically. After enabling this module, you can toggle the trailing slash setting at admin/config/search/clean-urls.

To avoid duplicate content issues (pages with and without a trailing slash), you should configure the following settings:

For Apache (.htaccess)

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} !=post [NC]
RewriteRule ^(.*(?:^|/)[^/\.]+)$ $1/ [L,R=301]

For IIS (web.config)

<configuration>
	<system.webServer>
		<rewrite>
			<rules>
				<rule name="Redirect to Trailing Slashes" enabled="true" stopProcessing="true">
 					<match url="^(.*(?:^|/)[^/\.]+)$" />
					<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
						<add input="{REQUEST_METHOD}" pattern="post" negate="true" />
					</conditions>
					<action type="Redirect" url="{R:1}/" />
				</rule>
			</rules>
		</rewrite>
	</system.webServer>
</configuration>

Alternatively, you can use the Global Redirect module to eliminate duplicate pages without manually configuring server settings.