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

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?

if youve rewritten you page to

 

http://site.com/extra/

 

and have a link:

 

style.css

 

its gonna look for the css in

 

http://site.com/extra/style.css not http://site.com/style.css

 

You can do this but i have never tried it, and you could make it worse - but its worth a shot

 

RewriteRule ^$  /

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.

Take away the define for testing . it wouldnt be too difficult to have the full path in the header without variables

 

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

 

If you cant do this make a header.php page and include it

The stylesheet is included in header.php

 

Tried

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

in the header.php without the php echo in the the link.

 

Still doesn't display the css if the modrewrite

 

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

 

is in the htaccess file.

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]

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.

Archived

This topic is now archived and is closed to further replies.

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