Jump to content

Making this same rewrite rule work without the slash at end of URL


adrianTNT

Recommended Posts

Hello.

I have this rule:

 

RewriteRule ^(.*)/ index.php?word=$1

 

Meaning that site/index.php?word=Adrian is also shown at site/adrian/

But how do I make it work without the slash at end too? site/adrian

 

I thing this should be simple but this is my first attempt with URL rewrite.

Thank you.

I assume you had your mod_rewrite working as you want it to be,

to make it optional, simply just put a ?, so it should be this.

RewriteRule ^(.*)/? index.php?word=$1

I tried this just now, It still works with the slash but if I do not enter the slash at end I get:

 

Not Found

The requested document was not found on this server.

 

Alright, how about this?

RewriteRule ^(.*)(/)? index.php?word=$1

That line and many other combinations I try makes it print the file name (index.php) because in index.php I only have echo $_GET['word']; so (that I can see if it works), the line you mentioned shows the right word that I type in url, the one without slash prints "index.php".

 

Maybe the problem is in php/apache settings? But in static site urls (without htaccess) if I do not type the slash it redirects me to the same url with slash at end, it does this by default.

 

Any other ideas?

Thank you.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.