Jump to content

Sooooooooooo easy, right?


lost305

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).

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.