Jump to content

Recommended Posts

This must be so easy but I can't figure it out.

 

how do i redirect

modules.php?name=News&file=article&sid=x

to

contenido/node/x

 

I tried...

 

# Enable rewrite engine 
Options +FollowSymLinks 
RewriteEngine on 
RewriteRule ^modules.php?name=News&file=article&sid=([0-9]+)$ contenido/node/$1

 

But that doesn't work. I'm very new to this and by what I've displayed you can tell I have no idea what I'm doing, but I bet it's so easy, right?

 

Can you explain please?

???

 

Thank you for your time. Any help will be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/110011-sooooooooooo-easy-right/
Share on other sites

Well I found this on another website and changed what I thought might work and voila!

 

<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteCond %{QUERY_STRING} ^name=News&file=article&sid=(.*)$

    RewriteRule ^modules.php$ /contenido/node/%1? [R=301,L]

</IfModule>

 

In case anyone has the same problem.

 

Funy I read somewhere else that I had to put a $1 instead of a %1

Also read to end the line with $ instead of ?

 

So confusing but I got it to work. If anyone can tell me how to do it better I would love you for ever

:o)

Well...  Err....  That will work, but if you want to know what was wrong with your first try, I shall explain:

 

RewriteRule takes a regular expression parameter, and in regular expressions, ? is a quantifier meant to mean optional.

 

For example

^Am I corbin?$

 

Would match 'Am I corbi' and 'Am I corbin,' not 'Am I corbin?'

 

^s?he

Would match anything starting with either she or he for another example.

 

So, to make the ? mean literally a question mark, you must escape it.

 

\ can be used (in this context) to escape things.

 

# Enable rewrite engine

Options +FollowSymLinks

RewriteEngine on

RewriteRule ^modules\.php\?name=News&file=article&sid=([0-9]+)$ contenido/node/$1

 

Oh!  I forgot until now to mention '.'

 

. means any character.  (So, that would match modulesaphp, modules.php, modulesb.php so on).

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.