jasmeet Posted November 22, 2013 Share Posted November 22, 2013 <?php $query=mysql_query("select * from category where pid=1"); while($result=mysql_fetch_array($query)){ ?> <a href="space1.php?name=<?php echo $result['name']; ?>"><?php echo $result['name']; ?></a> <?php } ?> in htaccess : RewriteEngine On RewriteRule ^([a-zA-Z0-9_-]+)$ space.php?name=$1 not working... Link to comment https://forums.phpfreaks.com/topic/284169-url-rewriting/ Share on other sites More sharing options...
dalecosp Posted November 22, 2013 Share Posted November 22, 2013 http://www.generateit.net/mod-rewrite/ Link to comment https://forums.phpfreaks.com/topic/284169-url-rewriting/#findComment-1459550 Share on other sites More sharing options...
Ch0cu3r Posted November 22, 2013 Share Posted November 22, 2013 Mod rewrite does not change your urls. It allows you to map fake urls to real ones. You need to change the links in your code so it outouts link in the format that you set your rewriterule to. So change your code (from the old url) <a href="space1.php?name=<?php echo $result['name']; ?>"><?php echo $result['name']; ?></a> to (the new url) <a href="/<?php echo $result['name']; ?>"><?php echo $result['name']; ?></a> The will output urls like site.com/name The site.com/name url will match the url for the rewriterule, and so when this type of url is request mod_rwrite will actually call site.com/space1.php?name=name Link to comment https://forums.phpfreaks.com/topic/284169-url-rewriting/#findComment-1459563 Share on other sites More sharing options...
jazzman1 Posted November 22, 2013 Share Posted November 22, 2013 @Ch0cu3r, I think, he/she wants to apply rewriting rule from space1.php?name=variable to space.php?name=variable. The easiest way is to get the query string after the file's extension. Assuming, the project directory is named: project. RewriteEngine on RewriteBase /project/ RewriteCond %{QUERY_STRING} ^name=([a-zA-Z]*)$ RewriteRule ^space1\.php$ space.php?name=%1 [R=301,L] Link to comment https://forums.phpfreaks.com/topic/284169-url-rewriting/#findComment-1459570 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.