frshjb373 Posted August 11, 2012 Share Posted August 11, 2012 I want to remove .php extension from all my urls. I've tried a ton of htaccess codes that I found on the web, but nothing seems to work. Isn't there a way to refer to a page within your site simply by naming the file name without the extension? For example, I currently have: <a href="birds.php">Birds</a> But how do I make something like the following work? <a href="birds">Birds</a> or <a href="/birds">Birds</a> Any help would be much appreciated. Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/266952-remove-php-from-url/ Share on other sites More sharing options...
cpd Posted August 11, 2012 Share Posted August 11, 2012 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) $1.php [QSA,L] Link to comment https://forums.phpfreaks.com/topic/266952-remove-php-from-url/#findComment-1368645 Share on other sites More sharing options...
frshjb373 Posted August 11, 2012 Author Share Posted August 11, 2012 Unfortunately that did not work. Should I be referring to my pages in the code without the .php or use a slash in front of the page? Also, the rule you provided broke my redirect code: RewriteEngine on <Files .htaccess> order allow,deny deny from all </Files> ErrorDocument 404 /404.php RewriteCond %{HTTP_HOST} ^joytothewild\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.joytothewild\.com$ RewriteRule ^(.*)$ "http\:\/\/www\.joytothewildphotos\.com\/$1" [R=301,L] Any other ideas? Also, thank you for the help. Link to comment https://forums.phpfreaks.com/topic/266952-remove-php-from-url/#findComment-1368647 Share on other sites More sharing options...
cpd Posted August 11, 2012 Share Posted August 11, 2012 Paste what you've done because you've got a redirect in there with a last option. Moreover, you've got unnecessary stuff in that file. RewriteCond %{HTTP_HOST} ^(www\.)?joytothewild\.com$ RewriteRule ^(.*)$ "http\:\/\/www\.joytothewildphotos\.com\/$1" [R=301,L] I'm not really sure what the deal with <Files> is but it looks like your denying the use of any htaccess files.... Link to comment https://forums.phpfreaks.com/topic/266952-remove-php-from-url/#findComment-1368655 Share on other sites More sharing options...
cpd Posted August 11, 2012 Share Posted August 11, 2012 And your escaping stuff you don't need to. Link to comment https://forums.phpfreaks.com/topic/266952-remove-php-from-url/#findComment-1368656 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.