Rewrite Rule help :(
12 posts
• Page 1 of 1
Rewrite Rule help :(
Hi there,
So sorry to bug everyone with what I am sure is a basic question, but I am tearing my hair out as I have never used this module before .
I basically need to create a simple rewrite rule which converts :
/blog.asp?title=the-blog-title-here
to :
/blog/the-blog-title-here
Can anyone help? I will be eternally thankful.
Thanks so much,
T
So sorry to bug everyone with what I am sure is a basic question, but I am tearing my hair out as I have never used this module before .
I basically need to create a simple rewrite rule which converts :
/blog.asp?title=the-blog-title-here
to :
/blog/the-blog-title-here
Can anyone help? I will be eternally thankful.
Thanks so much,
T
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Rewrite Rule help :(
Hello,
try using the following:
Regards
Andrew
try using the following:
- Code: Select all
RewriteEngine on
RewrteBase /
RewriteCond %{QUERY_STRING} ^title=([^&]+)$ [NC]
RewriteRule ^blog\.asp% /blog/%1? [Nc,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/([^/]+)$ /blog.asp?title=the-blog-title-here [NC,L]
Regards
Andrew
Re: Rewrite Rule help :(
Ah thanks so much Andrew.
Now sadly this didn't quite work, but getting somewhere... Also sorry just to be clear in my example the string I included is a variable so for example these would be a couple of examples of the re-write requirements (ie the title entry changes) :
/blog.asp?title=the-blog-title-here
/blog.asp?title=another-example-title
to (respectively) :
/blog/the-blog-title-here
/blog/another-example-title
(But naturally behind the scenes the page that it really needs to be querying, for dynamic content, is the original blog.asp?title=another-example-title, etc.)
Now, I have this, which is sort of working...
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} ^title=([^&]+)$ [NC]
RewriteRule ^blog\.asp$ blog/%1/? [NC,R=301,L]
BUT the problem I am having is that it is swapping the "-" for "%252D" as below :
/blog/another%252Dexample%252Dtitle/
And also, even if I physically type in: /blog/another-example-title it doesn't actually pull the content as if you were viewing : blog.asp?title=another-example-title
So sort of getting somewhere, but then not really!
So sorry to be such a pain, I am sure this is probably basic stuff for most - it is just such unfamiliar territory for me .
Many thanks again,
Tonya
Now sadly this didn't quite work, but getting somewhere... Also sorry just to be clear in my example the string I included is a variable so for example these would be a couple of examples of the re-write requirements (ie the title entry changes) :
/blog.asp?title=the-blog-title-here
/blog.asp?title=another-example-title
to (respectively) :
/blog/the-blog-title-here
/blog/another-example-title
(But naturally behind the scenes the page that it really needs to be querying, for dynamic content, is the original blog.asp?title=another-example-title, etc.)
Now, I have this, which is sort of working...
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} ^title=([^&]+)$ [NC]
RewriteRule ^blog\.asp$ blog/%1/? [NC,R=301,L]
BUT the problem I am having is that it is swapping the "-" for "%252D" as below :
/blog/another%252Dexample%252Dtitle/
And also, even if I physically type in: /blog/another-example-title it doesn't actually pull the content as if you were viewing : blog.asp?title=another-example-title
So sort of getting somewhere, but then not really!
So sorry to be such a pain, I am sure this is probably basic stuff for most - it is just such unfamiliar territory for me .
Many thanks again,
Tonya
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Rewrite Rule help :(
Hello,
That's encoding issue, try playing around with NE or NU flags. Their meanings are described here
The rule that has encoding issue is the first one, redirect. As the value of the variable is changed by the first one, the second one doesn't work too.
Regards
Andrew
That's encoding issue, try playing around with NE or NU flags. Their meanings are described here
The rule that has encoding issue is the first one, redirect. As the value of the variable is changed by the first one, the second one doesn't work too.
Regards
Andrew
Re: Rewrite Rule help :(
I suspect from the last comment that what you actually want to do is to rewrite the URLs in the *opposite* way from what you stated, e.g. the end-user keys:
www.example.com/blog/the-blog-title/here
and you want it to serve:
www.example.com/blog.asp?title=the-blog-title-here
Yes?
If so, you need:
RewriteRule blog/(.*)$ blog.asp?title=$1 [and whatever flags you need]
www.example.com/blog/the-blog-title/here
and you want it to serve:
www.example.com/blog.asp?title=the-blog-title-here
Yes?
If so, you need:
RewriteRule blog/(.*)$ blog.asp?title=$1 [and whatever flags you need]
Re: Rewrite Rule help :(
Hi there,
You are so right, and so sorry for the confusion caused there!!
What you have suggested works absolutely perfectly - so thank you sooooo much . Star!!
Tonya
You are so right, and so sorry for the confusion caused there!!
What you have suggested works absolutely perfectly - so thank you sooooo much . Star!!
Tonya
Re: Rewrite Rule help :(
Hello again,
Sorry, just wanted to check, for SEO reasons really, so now if I visit :
Link example 1 : http://www.example.com/blog/the-blog-title-here
It is of course in fact processing :
Link example 2 : http://www.example.com/blog.asp?title=t ... title-here (And I can of course still visit this link directly, and it still works)
BUT I just wondered, for SEO, is it bad that both these link formats are actually accessible simultaneously, and if so, is there a way of then setting another rule to say...
If you visit this link version 1 : /blog.asp?title=the-blog-title-here it then re-directs you in the address bar to link version 2 : /blog/the-blog-title-here
SO, in the browser address bar and in any search results, it would then ensure that it is this version which appears: /blog/the-blog-title-here
Hope I am making sense .
Many thanks again,
Tonya
Sorry, just wanted to check, for SEO reasons really, so now if I visit :
Link example 1 : http://www.example.com/blog/the-blog-title-here
It is of course in fact processing :
Link example 2 : http://www.example.com/blog.asp?title=t ... title-here (And I can of course still visit this link directly, and it still works)
BUT I just wondered, for SEO, is it bad that both these link formats are actually accessible simultaneously, and if so, is there a way of then setting another rule to say...
If you visit this link version 1 : /blog.asp?title=the-blog-title-here it then re-directs you in the address bar to link version 2 : /blog/the-blog-title-here
SO, in the browser address bar and in any search results, it would then ensure that it is this version which appears: /blog/the-blog-title-here
Hope I am making sense .
Many thanks again,
Tonya
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Rewrite Rule help :(
Yes, having 2 URL that server the same content - is duplicating content, which is bad for SEO.
That was the reason I provided you with 2 rules: 1) to make your URLs look nice, 2) to hide the old ugly URLs
Regards
Andrew
That was the reason I provided you with 2 rules: 1) to make your URLs look nice, 2) to hide the old ugly URLs
Regards
Andrew
Re: Rewrite Rule help :(
Hi Andrew,
Thanks for your reply, and so sorry for my dumbness on this !
Basically I had been unclear on my requirements originally, as someone else in this post then pointed out. So that sadly meant that your rules weren't what I was aiming for (as I say totally my bad explanations, not your mistake).
So I know this is what you supplied :
------------------------
RewriteCond %{QUERY_STRING} ^title=([^&]+)$ [NC]
RewriteRule ^blog\.asp% /blog/%1? [Nc,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/([^/]+)$ /blog.asp?title=the-blog-title-here [NC,L]
------------------------
But basically this is what I have now :
RewriteRule blog/(.*)$ blog.asp?title=$1 [L]
(This basically makes this URL : /blog/entry-title-here to process /blog.asp?title=entry-title-here).
So I just need the rule which says if I manually access this format /blog.asp?title=entry-title-here to in turn jump me to /blog/entry-title-here
Now I have tried adding in those additional elements you included (and tweaked to try different things) to handle this double URL problem, but sadly it is not quite working.
Please could you let me know what additional rules I need to add to the above to handle this . God I hope I am making sense!!
Thanks so much,
Tonya
Thanks for your reply, and so sorry for my dumbness on this !
Basically I had been unclear on my requirements originally, as someone else in this post then pointed out. So that sadly meant that your rules weren't what I was aiming for (as I say totally my bad explanations, not your mistake).
So I know this is what you supplied :
------------------------
RewriteCond %{QUERY_STRING} ^title=([^&]+)$ [NC]
RewriteRule ^blog\.asp% /blog/%1? [Nc,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/([^/]+)$ /blog.asp?title=the-blog-title-here [NC,L]
------------------------
But basically this is what I have now :
RewriteRule blog/(.*)$ blog.asp?title=$1 [L]
(This basically makes this URL : /blog/entry-title-here to process /blog.asp?title=entry-title-here).
So I just need the rule which says if I manually access this format /blog.asp?title=entry-title-here to in turn jump me to /blog/entry-title-here
Now I have tried adding in those additional elements you included (and tweaked to try different things) to handle this double URL problem, but sadly it is not quite working.
Please could you let me know what additional rules I need to add to the above to handle this . God I hope I am making sense!!
Thanks so much,
Tonya
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Rewrite Rule help :(
Tonya, everything you need is already there. If you'd look more carefully, the rule you use is the second one from those I suggested(mine just has 2 additional conditions, just in case). The first one achieves the results you need. It's just that I made a small typo there, replace '%' with '$' as in the following:
Regards
Andrew
- Code: Select all
RewriteCond %{QUERY_STRING} ^title=([^&]+)$ [NC]
RewriteRule ^blog\.asp$ /blog/%1? [NC,R=301,L]
Regards
Andrew
Re: Rewrite Rule help :(
My god, I am so sorry - what a total muppet I am!!! You are right I should have noticed that!!!! I am definitely getting more familiar with all this now...
Thanks so much Andrew - you are a total star and your help is SOOOOOOO much appreciated .
Tonya
Thanks so much Andrew - you are a total star and your help is SOOOOOOO much appreciated .
Tonya
12 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 0 guests