Forum Moderators: phranque

Message Too Old, No Replies

How to rewrite with - in the url but get the page to show?

mod rewrite replace -

         

emotn

5:59 am on Jan 11, 2012 (gmt 0)

10+ Year Member



Hi,

I am new to .htaccess and am trying to get it to rewrite - I have this code and it sort of works:

RewriteRule ^[A-Z0-9_-]+\.html /topic.php?Topic=$1 [NC,L]


the mysite.com/This-Is-The-Page.html partly shows - ie: all of the graphics and layouts but not the content.


If I enter the URL mysite.com/topic.php?Topic=This-Is-The-Page it comes up and the content as well.


On the topic.php page I have

$CatName = str_replace("-", " ", $_GET['Topic']);


and I do a query on the mysql database taken from the $CatName

I am guessing I am missing a step or character somewhere in the .htaccess or the php?

Any help and guidance to get this working will be much appreciated.

Thank you for your time.

lucy24

8:34 am on Jan 11, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



$1 means reuse a capture. Your Rule as written doesn't capture anything. Is all or part of the original URL supposed to turn into a query string?

If the page works as intended when you enter the URL manually, then you need not worry about additional mistakes in the php.

g1smd

8:51 am on Jan 11, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



$1 is empty. You need to capture the text to go in it.

emotn

9:43 am on Jan 11, 2012 (gmt 0)

10+ Year Member



Thank you both for your answers - they pointed me in the right direction to find the answer!

I have changed my string and got it to work now - ok without the .html at the end but how to remove that would have been my next question :)

For anyone else who needs to do this here is what worked for me

RewriteRule ^([A-Z0-9_-]+)?$ topic.php?Topic=$1 [NC,L]