Ignore trailing slash with Apache Rewrite
Asked Answered
O

1

7

I'm using mod_rewrite to redirect like so:

RewriteRule (work)/?$ $1.php [L]

This sends any URL ending in /work or /work/ to work.php

The problem is, when a trailing slash is included, it treats it as a directory, and not the file that it really is. This, of course, breaks all of my relative paths in the file.

I don't mind having a slash in the URL, but is there any way to use Apache to ignore the trailing slash, and treat the URL as a file, just as it would without the slash?

Own answered 1/10, 2011 at 18:9 Comment(2)
do you have a "work" directory?Cutlet
do you have anything else in the .htaccess or vhost?Cutlet
C
11

Since you don't want the URL to look like www.domain.com/work/ here's what you can do:

  RewriteEngine On
  RewriteRule ^work/$ http://www.domain.com/work%{REQUEST_URI} [R=301,L,NC]
  RewriteRule (work)$ $1.php [L,QSA,NC]

This will redirect /work/ to /work and /work/?page=main to /work?page=main

Cutlet answered 1/10, 2011 at 22:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.