Jump to content

.htaccess


signature16

Recommended Posts

I've been trying to make my URLs friendly, but it never seems to work correctly.

 

This is the code I'm using on my index page:

 

<?php 
$id = $_REQUEST['id'];
if($id == "") {
$id = "index";
}  include "pages/$id.php";  
?>

 

It creates links that look like this:  www.website.com/index.php?id=random-webpage

 

 

How can I convert those links into:  www.website.com/random-webpage.php

 

 

 

 

Link to comment
Share on other sites

Always fun.

 

You need some type of filter, but for the most part any request needs to be ported through a processing file.

 

In this file I would do a check to see if the random-webpage.php exists. If it does than you send the user to that page if not, than it is a fake and you split up the file name and pass it to the correct location using the include as you have shown.

 

It is more complicated than explained, but that is the gist of it.

Link to comment
Share on other sites

something like this in .htaccess:

 

RewriteEngine On
RewriteRule ^random-webpage\.php$ /index.php?id=random-webpage [L,NC]

 

or if you will pass through ALL urls, something more like this (neither of these tested):

 

RewriteEngine On
RewriteRule ^(!index\.php)$ /index.php?id=$1 [L,NC]

Link to comment
Share on other sites

and if you want to send real pages to the browser without substitution, put this before all other rewrites:

 

# Don't rewrite real files or directories after this point.
RewriteCond %{SCRIPT_FILENAME} -f [OR]
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule .* - [L]

 

so i guess this would be the whole thing:

 

RewriteEngine On

# Don't rewrite real files or directories after this point.
RewriteCond %{SCRIPT_FILENAME} -f [OR]
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule .* - [L]

RewriteRule ^(!index\.php)$ /index.php?id=$1 [L,NC]

Link to comment
Share on other sites

I would post the code I used, but I have customized it so much there is too much to filter. That and I consider it proprietary information due to certain aspects of it.

 

Anyhow a simple google search will provide you with more than enough information.

 

http://www.google.com/search?hl=en&q=php+seo+friendly+url&btnG=Google+Search

 

http://www.sitepoint.com/article/search-engine-friendly-urls

 

http://techie-buzz.com/ask-techie/create-seo-friendly-urls-using-mod-rewrite-and-php-part-1.html

 

 

A few different ways, which is best for you is for you to choose.

 

 

Link to comment
Share on other sites

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.