PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > alt.apache.configuration > Add trailing slash if not present.
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
alt.apache.configuration Apache web server configuration issues.

Add trailing slash if not present.

Réponse
 
LinkBack Outils de la discussion
Vieux 09/01/2008, 13h27   #1
Wizz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Add trailing slash if not present.

Hey guys,

I'm busy with a project, but because I'm such a bitch about details I
want to solve this.

I want to add a trailing slash to the url if it is not present.

for example:
http://mydomain.com/products/books

should be rewritten to:
http://mydomain.com/products/books/

Currently I have a few rules in my .htaccess file:

---
Options +FollowSymLinks

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !^.*\.(gif|jpg|jpeg|png|js|css)$ [NC]
RewriteRule ^(.*)$ index.php [L]
---

But how would I go about checking if it ends with a slash?

Greetz,

Wizz
  Réponse avec citation
Vieux 09/01/2008, 18h08   #2
Wizz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Add trailing slash if not present.

To elaborate on the current RewriteRules: I handle all the request
through a php script inside index.php. It does work now, I just think
it looks better with the trailing slash...

Greetz,

Wizz

On Jan 9, 2:27 pm, Wizz <woutaw...@gmail.com> wrote:
> Hey guys,
>
> I'm busy with a project, but because I'm such a bitch about details I
> want to solve this.
>
> I want to add a trailing slash to the url if it is not present.
>
> for example:http://mydomain.com/products/books
>
> should be rewritten to:http://mydomain.com/products/books/
>
> Currently I have a few rules in my .htaccess file:
>
> ---
> Options +FollowSymLinks
>
> RewriteEngine on
> RewriteBase /
>
> RewriteCond %{REQUEST_FILENAME} !^.*\.(gif|jpg|jpeg|png|js|css)$ [NC]
> RewriteRule ^(.*)$ index.php [L]
> ---
>
> But how would I go about checking if it ends with a slash?
>
> Greetz,
>
> Wizz


  Réponse avec citation
Vieux 09/01/2008, 18h59   #3
HansH
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Add trailing slash if not present.


"Wizz" <woutawizz@gmail.com> schreef in bericht
news:34ac85d4-b91d-4ffa-a00c-1d90e0497fb7@21g2000hsj.googlegroups.com...
>> On Jan 9, 2:27 pm, Wizz <woutaw...@gmail.com> wrote:
>> Hey guys,
>>
>> I'm busy with a project, but because I'm such a bitch about details

Yet another detail ... first quote than response is the usenet habbit

>> Options +FollowSymLinks
>>
>> RewriteEngine on
>> RewriteBase /
>>
>> RewriteCond %{REQUEST_FILENAME} !^.*\.(gif|jpg|jpeg|png|js|css)$ [NC]
>> RewriteRule ^(.*)$ index.php [L]
>> ---
>>
>> But how would I go about checking if it ends with a slash?

In fact how to test for being both extentionless AND trailing-slashless:
RewriteCond %{REQUEST_URI} !\.[^/]+$|/$ [NC]
RewriteRule (.*) $1/ [R,QSA]

RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|js|css)$ [NC]
RewriteRule . index.php [L]

> To elaborate on the current RewriteRules: I handle all the request
> through a php script inside index.php. It does work now, I just think
> it looks better with the trailing slash...

If details do bother you rather have your script(s) and template(s) generate
the slash than make a browser ask twice.


HansH




  Réponse avec citation
Vieux 10/01/2008, 09h15   #4
phantom
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Add trailing slash if not present.

"Wizz" <woutawizz@gmail.com> wrote in message
news:34ac85d4-b91d-4ffa-a00c-1d90e0497fb7@21g2000hsj.googlegroups.com...
> On Jan 9, 2:27 pm, Wizz <woutaw...@gmail.com> wrote:
>> Hey guys,
>>
>> I'm busy with a project, but because I'm such a bitch about details I
>> want to solve this.
>>
>> I want to add a trailing slash to the url if it is not present.
>>
>> for example:http://mydomain.com/products/books
>>
>> should be rewritten to:http://mydomain.com/products/books/
>>

<SNIP>
> To elaborate on the current RewriteRules: I handle all the request
> through a php script inside index.php. It does work now, I just think
> it looks better with the trailing slash...
>


You could do this in your php script with something like:
if (<no slash on the end>) {
Header("Location: http://mydomain.com/products/books/");
die;
}



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h28.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13433 seconds with 12 queries