Hi,
I think this is a rather simple thing to solve, but I've been unable to do it so far !!
I have several redirect rules set up in my .htaccess (most of them involving regex), but I am unable to get the following one working:
1. I need to be able to redirect all requests coming to ".../?n=X" to "http://mysite.com/names/X" - I am unable to match the "\?n=*" part using regex!
Can somebody please help me.
Any help will be of great value to me. Thanks in advance.
Regex Trouble
Moderator: General Moderators
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Regex Trouble
Try this:
(untested!)
Code: Select all
RewriteRule ^.*/[?]n=([^/]+)/?$ names/$1Re: Regex Trouble
Hi prometheuzz,
Thank you very much for the help.
However, the solution you suggested is not working, as it is somehow continuing to not match the "?n=X" part (where X is the only thing that can change, for ex: X can be 1, 34, 4567 etc..)
Thank You.
Thank you very much for the help.
However, the solution you suggested is not working, as it is somehow continuing to not match the "?n=X" part (where X is the only thing that can change, for ex: X can be 1, 34, 4567 etc..)
Thank You.
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Regex Trouble
I'm not sure what you mean by "continuing to not match the "?n=X" part". Could you tell me what IS and what ISN'T matched when you use my suggestion?vjeleven wrote:Hi prometheuzz,
Thank you very much for the help.
However, the solution you suggested is not working, as it is somehow continuing to not match the "?n=X" part (where X is the only thing that can change, for ex: X can be 1, 34, 4567 etc..)
Thank You.
Note that I don't have access to an Apache server with that module installed, so my help is rather limited.
Good luck.
Re: Regex Trouble
Hi prometheuzz,
For ex:
if i am giving a simple redirect rule like:
RewriteRule n=1234 http://mysite.com
it is correctly when redirecting when we try a URL thats like .../n=1234
Now, when I try to The moment I put in the '?' mark before it, it does not match
As you suggested, i tried:
RewriteRule ^.*/[?]n=([^/]+)/?$ names/$1
But it does not work and gives me a 404 !! And the 404 is not because names/X does not exist. It does exist.
Thank You.
For ex:
if i am giving a simple redirect rule like:
RewriteRule n=1234 http://mysite.com
it is correctly when redirecting when we try a URL thats like .../n=1234
Now, when I try to The moment I put in the '?' mark before it, it does not match
As you suggested, i tried:
RewriteRule ^.*/[?]n=([^/]+)/?$ names/$1
But it does not work and gives me a 404 !! And the 404 is not because names/X does not exist. It does exist.
Thank You.
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Regex Trouble
What happens when you provide the entire url:vjeleven wrote:Hi prometheuzz,
For ex:
if i am giving a simple redirect rule like:
RewriteRule n=1234 http://mysite.com
it is correctly when redirecting when we try a URL thats like .../n=1234
Now, when I try to The moment I put in the '?' mark before it, it does not match
As you suggested, i tried:
RewriteRule ^.*/[?]n=([^/]+)/?$ names/$1
But it does not work and gives me a 404 !! And the 404 is not because names/X does not exist. It does exist.
Thank You.
Code: Select all
RewriteRule ^.*/[?]n=([^/]+)/?$ http://mysite.com/names/$1Good luck!