Adding trailing slash .htaccess

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!

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

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

Hey man. Doesn’t work.

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

Ah, then its probably multiviews at play.

Try adding

Options -MultiViews

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:

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

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

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]

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.

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]

?

Alternatively, could you try this?

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

Allright. Got it.

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

Doesn’t work. “Object not found”

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

Should I have folders before dresses?

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?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.