Jump to content

Recommended Posts

<?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

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

Edited by Ch0cu3r
Link to comment
https://forums.phpfreaks.com/topic/284169-url-rewriting/#findComment-1459563
Share on other sites

@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]

Edited by jazzman1
Link to comment
https://forums.phpfreaks.com/topic/284169-url-rewriting/#findComment-1459570
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.