Help with Removing File Extentions

New to mod_rewrite? This is a good place to start.

Postby Gus » Wed Oct 14, 2009 1:11 pm

If I want to force a trailing slash, how would I go about to add that to what I currently have?

Code: Select all
Options +FollowSymLinks -MultiViews

RewriteRule ^work/?$ /v5/work/print/ [R=301,L]

RewriteEngine On

# Redirect to remove /index.php files.
RewriteCond %{THE_REQUEST} \ /(.+/)?index\.php(\?.*)?\  [NC]
RewriteRule ^(.+/)?index\.php$ /%1 [NC,R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^about\.php$ /v5/about/ [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^blog\.php$ /blog/ [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^contact\.php$ /contact/ [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^work\.php$ /v5/work/print/ [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^identity\.php$ /v5/work/identity/ [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^web\.php$ /v5/work/web/ [R=301,L]

RewriteRule ^about/?$ /v5/about.php [QSA,L]
RewriteRule ^blog/?$ /blog.php [QSA,L]
RewriteRule ^contact/?$ /v5/contact.php [QSA,L]

RewriteRule ^work/print/?$ /v5/work.php [QSA,L]
RewriteRule ^work/identity/?$ /v5/identity.php [QSA,L]
RewriteRule ^work/web/?$ /v5/web.php [QSA,L]


Thanks!

Gus
Gus
 
Posts: 7
Joined: Sun Sep 27, 2009 4:11 pm
Location: London

Postby richardk » Wed Oct 14, 2009 2:23 pm

Try adding
Code: Select all
RewriteRule ^(about|blog|contact|work(print|identity|web))$ %{REQUEST_URI}/ [R=301,L]

with the other redirects.

Or
Code: Select all
# If it's not a file
RewriteCond %{SCRIPT_FILENAME} !-f
# and it doesn't have a trailing slash, force a trailing slash.
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Previous

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 6 guests

cron