Home Remove trailing slash and then execute successive RewriteCond statements
Reply: 1

Remove trailing slash and then execute successive RewriteCond statements

Mallikarjun M
1#
Mallikarjun M Published in 2018-01-09 13:35:46Z

My website have some of the links ending with slash (/). Following are some of the example links of my site.

  1. www.website/foo/
  2. www.website/bar

Following is the .htaccess file,

    <IfModule mod_rewrite.c>

    RewriteEngine on

    RewriteCond "%{DOCUMENT_ROOT}/static/%{REQUEST_URI}.html"  -f
    RewriteRule "^(.+)" "%{DOCUMENT_ROOT}/static/$1.html"  [L]

    </IfModule>

In the .htaccess file, I am checking if there is an html file with the same name of REQUEST_URI in static directory.

www.website/bar is working fine.

www.website/foo/ is not working. That is obvious, because there is a trailing slash.

Please help me to remove the trailing slash and check if the html version of REQUEST_URI is present.

starkeen
2#
starkeen Reply to 2018-01-10 12:41:09Z

You need to match the slash outside the capture group. ^(.+)/ will match /foo/ or any uri string ending with a slash. To match both non-trailing slash and Trailing slash uris just put a ? at the end ^(.+)/? .

Update your Rule with the following:

 RewriteRule "^(.+)/?" "%{DOCUMENT_ROOT}/static/$1.html"  [L]
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.333947 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO