Adding trailing slash .htaccess


#1

Hello.

Lets say that I have a file called "somefile.php".

When I link to that file with a added slash like this: "somefile.php/somethingwhatever" I still get somefile.php. this is good, this is what I want.

The problem is that now that I have removed the .php using Rewrite in .htacess, this doesn't work with info after a slash. Of course, just typing "somefile" instead of "somefile.php" will now work after I added Rewrite to .htacess. But I want it to work with the extra info after the slash as well.

this link will work: "somefile.php/somethingwhatever"

this will not work, but this is what I want: "somefile/somethingwhatever"

Will it get mixed up and think it should look for a folder? Or is there something I can do to fix this?

Bless!


#2

RewriteEngine On
RewriteRule ^somefile/(.*) /somefile.php/$1 [L]

That should work. And indeed you would need one rule per file.


#3

Hey man. Doesn't work.

somefile.php/randominfo works, but not somefile/randominfo. I get "object not found"


#4

Ah, then its probably multiviews at play.

Try adding

Options -MultiViews

#5

It doesn't work either unfortunately :confused:

My goal is to have links like this:

www.website.com/homepage/dresses
www.website.com/homepage/shirts
www.website.com/homepage/jackets.. and so on, twenty more for both men and women...

I could just create a empty foldercategory for each category that I have and then put an index file in each and everyone of them. But it feels like it should be an easier way to do this just from one source.

And I dont want to use GET-method to do something similar. I want the slashes :slight_smile:


#6

Could you post the full .htaccess file you have now?


#7

Sure.
I tried with this first:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)$ $1.php [L]

then this:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)$ $1.php [L]

RewriteEngine On
RewriteRule ^dresses/(.*) /dresses.php/$1 [L]

Options -MultiViews

#8

Order matters. Try it like this:

Options -MultiViews

RewriteEngine On

RewriteRule ^dresses/(.*) /dresses.php/$1 [L]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+)$ $1.php [L]

#9

Not now either. But you mentioned that I have to make a htaccess file for each category if we can get this to work. If so, there is no big difference between the option where I fix the htacess file or if I make a folder for each category and add an index file to each folder. Right?

I'm open to other solutions as well, if you know any.


#10

No not one htaccess file per directory, one RewriteRule per directory. One htaccess file.

Weird that it won't work. I don't see anything wrong with it.

What happens when you remove

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+)$ $1.php [L]

?


#11

Alternatively, could you try this?

RewriteRule ^dresses/(.*) /dresses.php

#12

Allright. Got it.

When I remove those lines I have to add .php to the url


#13

Doesn't work. "Object not found"


#14

RewriteRule ^dresses/(.*) /dresses.php/$1 [L]

Should I have folders before dresses?


#15

I don't know what you tell you at this point. Your web server doesn't seem to be behaving like it should.
Are you sure you're using Apache web server?