Jump to content

[SOLVED] How can I mod rewrite similiar to localhost.com/idnumber ?


pneudralics

Recommended Posts

How can I mod rewrite similiar to localhost.com/idnumber ?

Tried the following in htacess

RewriteRule ^/(.*)$ member.php?id=$1 [NC,L]

 

and this in my php file

<a href="/<?php echo"$id"; ?>

 

I want to be able to have localhost.com/idnumber instead of

localhost.com/member.php?id=idnumber

Link to comment
Share on other sites

I have my website url setup this in my connect.php file:

define ('WEBSITEURL', 'http://localhost);

 

Every link on all my pages are setup as /page.php

 

So...how can I fix this other than going through all my php files looking for all the links and change it to page.php without the slash?

Link to comment
Share on other sites

define ('WEBSITEURL', 'http://localhost');

<link rel="stylesheet" type="text/css" href="<?php echo WEBSITEURL; ?>/style.css" />

 

When I viewsource with the modrewrite on it shows the below without any style in the browser so everything is messed up:

<link rel="stylesheet" type="text/css" href="http://localhost/style.css" />

 

With the modrewrite removed it shows the same but the css displays.

Link to comment
Share on other sites

The problem is with your RewriteRule. This line is too greedy

 

RewriteRule ^([^/]+)?/?$ member.php?id=$1 [L,QSA]

 

With that line everything will be sent to member.php?id=whatever

 

If all you want is site.com/123 to be sent to member.php?id=123 You should use

 

RewriteRule ^([0-9]+)?/?$ member.php?id=$1 [L,QSA]

 

You should should add a couple of conditions so existing files/folders do not get affected by your rewriteRules

 

Corrected code

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([0-9]+)?/?$ member.php?id=$1 [L,QSA]

Link to comment
Share on other sites

The problem is with your RewriteRule. This line is too greedy

 

RewriteRule ^([^/]+)?/?$ member.php?id=$1 [L,QSA]

 

With that line everything will be sent to member.php?id=whatever

 

If all you want is site.com/123 to be sent to member.php?id=123 You should use

 

RewriteRule ^([0-9]+)?/?$ member.php?id=$1 [L,QSA]

 

You should should add a couple of conditions so existing files/folders do not get affected by your rewriteRules

 

Corrected code

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([0-9]+)?/?$ member.php?id=$1 [L,QSA]

 

Thanks worked perfectly. Sorry I got side tracked from this.

Link to comment
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.