Jump to content

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.

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.