r0b Posted May 13, 2011 Share Posted May 13, 2011 I'm currently using Options +FollowSymLinks Options +Indexes RewriteEngine on RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([^\.]+)$ $1.php [NC,L] for changing urls from example.com/pagename.php to example.com/pagename I recently finished a CMS which has uses urls like example.com/?page=Pagename Could anyone help me with the htaccess code for chaning the example.com/?page=Pagename to just example.com/pagename Would something like this work? Options +FollowSymLinks Options +Indexes RewriteEngine on RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([^\.]+)$ ?page=$1.php [NC,L] Link to comment https://forums.phpfreaks.com/topic/236299-nice-urls-not-working/ Share on other sites More sharing options...
r0b Posted May 13, 2011 Author Share Posted May 13, 2011 Seconds later I just think I figured it out, this works, is the code okay? Options +FollowSymLinks Options +Indexes RewriteEngine on RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([^\.]+)$ ?page=$1 [NC,L] And am is this a valid looking htaccess file? (posting the whole htaccess) # more password protection <Files password> order allow,deny deny from all </Files> Options +FollowSymLinks Options +Indexes RewriteEngine on RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([^\.]+)$ ?page=$1 [NC,L] Link to comment https://forums.phpfreaks.com/topic/236299-nice-urls-not-working/#findComment-1214892 Share on other sites More sharing options...
r0b Posted May 13, 2011 Author Share Posted May 13, 2011 The code works just fine, its causing one problem: When logging into the admin panel from a page for example example.com/Home trying to login to the administration panel to example.com/?login the link becomes example.com/Home?login. This problem doesn't occur if I login directly to the admin panel from example.com Link to comment https://forums.phpfreaks.com/topic/236299-nice-urls-not-working/#findComment-1214894 Share on other sites More sharing options...
r0b Posted May 13, 2011 Author Share Posted May 13, 2011 Solved this with three lines on the index.php $hostname = $_SERVER['PHP_SELF']; $hostname = str_replace('index.php', '', $hostname); $hostname = str_replace($page, '', $hostname); Cheers Link to comment https://forums.phpfreaks.com/topic/236299-nice-urls-not-working/#findComment-1214898 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.