pneudralics Posted June 2, 2009 Share Posted June 2, 2009 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 https://forums.phpfreaks.com/topic/160710-solved-how-can-i-mod-rewrite-similiar-to-localhostcomidnumber/ Share on other sites More sharing options...
dreamwest Posted June 2, 2009 Share Posted June 2, 2009 RewriteEngine On RewriteRule ^([^/]+)?/?$ member.php?id=$1 [L,QSA] Link to comment https://forums.phpfreaks.com/topic/160710-solved-how-can-i-mod-rewrite-similiar-to-localhostcomidnumber/#findComment-848149 Share on other sites More sharing options...
pneudralics Posted June 2, 2009 Author Share Posted June 2, 2009 RewriteEngine On RewriteRule ^([^/]+)?/?$ member.php?id=$1 [L,QSA] Thanks that made it work, but for some reason it threw off my css file, so when I look at my localhost it looks all messed up. Link to comment https://forums.phpfreaks.com/topic/160710-solved-how-can-i-mod-rewrite-similiar-to-localhostcomidnumber/#findComment-848154 Share on other sites More sharing options...
dreamwest Posted June 2, 2009 Share Posted June 2, 2009 It wouldnt do that, you have wrong path for your css. Is it style.css instead of /style.css post a link Link to comment https://forums.phpfreaks.com/topic/160710-solved-how-can-i-mod-rewrite-similiar-to-localhostcomidnumber/#findComment-848156 Share on other sites More sharing options...
pneudralics Posted June 2, 2009 Author Share Posted June 2, 2009 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 https://forums.phpfreaks.com/topic/160710-solved-how-can-i-mod-rewrite-similiar-to-localhostcomidnumber/#findComment-848165 Share on other sites More sharing options...
dreamwest Posted June 2, 2009 Share Posted June 2, 2009 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 ^$ / Link to comment https://forums.phpfreaks.com/topic/160710-solved-how-can-i-mod-rewrite-similiar-to-localhostcomidnumber/#findComment-848166 Share on other sites More sharing options...
pneudralics Posted June 2, 2009 Author Share Posted June 2, 2009 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 https://forums.phpfreaks.com/topic/160710-solved-how-can-i-mod-rewrite-similiar-to-localhostcomidnumber/#findComment-848182 Share on other sites More sharing options...
dreamwest Posted June 2, 2009 Share Posted June 2, 2009 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 Link to comment https://forums.phpfreaks.com/topic/160710-solved-how-can-i-mod-rewrite-similiar-to-localhostcomidnumber/#findComment-848202 Share on other sites More sharing options...
pneudralics Posted June 3, 2009 Author Share Posted June 3, 2009 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. Link to comment https://forums.phpfreaks.com/topic/160710-solved-how-can-i-mod-rewrite-similiar-to-localhostcomidnumber/#findComment-848334 Share on other sites More sharing options...
dreamwest Posted June 3, 2009 Share Posted June 3, 2009 Post a link to your site and i can tell you whats happening Link to comment https://forums.phpfreaks.com/topic/160710-solved-how-can-i-mod-rewrite-similiar-to-localhostcomidnumber/#findComment-848341 Share on other sites More sharing options...
wildteen88 Posted June 3, 2009 Share Posted June 3, 2009 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 https://forums.phpfreaks.com/topic/160710-solved-how-can-i-mod-rewrite-similiar-to-localhostcomidnumber/#findComment-848727 Share on other sites More sharing options...
pneudralics Posted June 8, 2009 Author Share Posted June 8, 2009 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 https://forums.phpfreaks.com/topic/160710-solved-how-can-i-mod-rewrite-similiar-to-localhostcomidnumber/#findComment-851245 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.