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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.