473,326 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

.htaccess and PHP

Nel
Just looking for some general advice on modifying the URL for php.

I am using .htaccess to allow a web site to translate example.html to
index.php?content=example
(below)

ErrorDocument 404 http://www.example.com
RewriteEngine on
RewriteRule ^/?(.*).html$ /index.php?content=$1 [L]

Is there any downside to using this method. I just want to know before I
roll it out over several other sites.

Nel.
Jul 17 '05 #1
7 3672
Nel wrote:
Just looking for some general advice on modifying the URL for php.

I am using .htaccess to allow a web site to translate example.html to
index.php?content=example
(below)

ErrorDocument 404 http://www.example.com
RewriteEngine on
RewriteRule ^/?(.*).html$ /index.php?content=$1 [L]

Is there any downside to using this method. I just want to know before I
roll it out over several other sites.


This is a similar approach to what I've used on a handful of sites
(20-30). I haven't experienced any downside to this yet - unless there
is a problem on the server with the mod_rewrite or you are going to a
server other than Apache like zues or *gasp* IIS - in which case you'd
have to hope that ISAPI_rewrite and whatever Zues uses is compatible
enough to get you through.

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
Jul 17 '05 #2
"Nel" <ne***@ne14.co.NOSPAMuk> wrote in news:DwGxc.12894$NK4.1841718
@stones.force9.net:
Just looking for some general advice on modifying the URL for php.

I am using .htaccess to allow a web site to translate example.html to
index.php?content=example
(below)

ErrorDocument 404 http://www.example.com
RewriteEngine on
RewriteRule ^/?(.*).html$ /index.php?content=$1 [L]

Is there any downside to using this method. I just want to know before I roll it out over several other sites.

Nel.


Nel,

I use something similar.
1) I redirect alias domains and domains without www. in front to my main
domain using a 301 redirect which is what Google likes in order to
maintain pagerank.
2) I test to make sure the page being requested is not a file or
directory that exists. If it exists, then retrive the existing page.
This is nice in case you want to have a pages that are not part of your
content management system.
3) I don't just redirect pages with .html extensions. I redirect
everything into content management system and then the cms parses the
requested page and strips extensions, trailing slashes, etc.

Options +SymlinksIfOwnerMatch

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.rootmode\.com
RewriteRule ^(.*)$ http://www\.rootmode\.com/$1 [R=
301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ $1 [L]

RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule ^(.*)$ /index.php?page=$1 [L]
--
Edward Alfert
http://www.rootmode.com/
Multiple Domain Hosting and Reseller Hosting Plans
Coupon Code (Recurring $5/month Discount): newsgroup

Jul 17 '05 #3
"Nel" <ne***@ne14.co.NOSPAMuk> wrote in message
news:Dw*********************@stones.force9.net...
Just looking for some general advice on modifying the URL for php.

I am using .htaccess to allow a web site to translate example.html to
index.php?content=example
(below)

ErrorDocument 404 http://www.example.com
RewriteEngine on
RewriteRule ^/?(.*).html$ /index.php?content=$1 [L]

Is there any downside to using this method. I just want to know before I
roll it out over several other sites.


Other then losing the ability to use regular .html files, there's no major
downside I can think of. Then again, there's little upside to doing things
this way. If you don't need to use Apache rewrite, my advise is to not use
it.
Jul 17 '05 #4
Nel
"Edward Alfert" <ea*****@rootmode.com> wrote in message
news:Xn********************************@130.133.1. 4...
"Nel" <ne***@ne14.co.NOSPAMuk> wrote in news:DwGxc.12894$NK4.1841718
@stones.force9.net:
Just looking for some general advice on modifying the URL for php.

I am using .htaccess to allow a web site to translate example.html to
index.php?content=example
(below)

ErrorDocument 404 http://www.example.com
RewriteEngine on
RewriteRule ^/?(.*).html$ /index.php?content=$1 [L]

Is there any downside to using this method. I just want to know before I
roll it out over several other sites.

Nel.


Nel,

I use something similar.
1) I redirect alias domains and domains without www. in front to my main
domain using a 301 redirect which is what Google likes in order to
maintain pagerank.
2) I test to make sure the page being requested is not a file or
directory that exists. If it exists, then retrive the existing page.
This is nice in case you want to have a pages that are not part of your
content management system.
3) I don't just redirect pages with .html extensions. I redirect
everything into content management system and then the cms parses the
requested page and strips extensions, trailing slashes, etc.

Options +SymlinksIfOwnerMatch

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.rootmode\.com
RewriteRule ^(.*)$ http://www\.rootmode\.com/$1 [R=
301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ $1 [L]

RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule ^(.*)$ /index.php?page=$1 [L]
--
Edward Alfert
http://www.rootmode.com/
Multiple Domain Hosting and Reseller Hosting Plans
Coupon Code (Recurring $5/month Discount): newsgroup


One of the reasons I am using .html is to give the site the look and feel of
a static html web site. I was under the impression, that with some
exceptions (like Google) search engines list the pages better than
index.php?content=example.
2) I test to make sure the page being requested is not a file or
directory that exists. If it exists, then retrive the existing page.
This is nice in case you want to have a pages that are not part of your
content management system.

If I need a stand alone page, it will probably have some php requirement, so
I would probably just call existing pages example.php. I'm not likely to
ever have static html files that could not be moved over to content
management.

Thanks for the detailed feedback. I had a look at your web site and see
what you mean. It works very well! :-)

Nel.
Jul 17 '05 #5
Nel
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:SK********************@comcast.com...
"Nel" <ne***@ne14.co.NOSPAMuk> wrote in message
news:Dw*********************@stones.force9.net...
Just looking for some general advice on modifying the URL for php.

I am using .htaccess to allow a web site to translate example.html to
index.php?content=example
(below)

ErrorDocument 404 http://www.example.com
RewriteEngine on
RewriteRule ^/?(.*).html$ /index.php?content=$1 [L]

Is there any downside to using this method. I just want to know before I roll it out over several other sites.


Other then losing the ability to use regular .html files, there's no major
downside I can think of. Then again, there's little upside to doing things
this way. If you don't need to use Apache rewrite, my advise is to not use
it.

As I just posted above Chung, I was under the impression that example.html
was easier for search engines to map.

Nel
Jul 17 '05 #6
"Nel" <ne***@ne14.co.NOSPAMuk> wrote in
news:Lv*********************@stones.force9.net:
"Edward Alfert" <ea*****@rootmode.com> wrote in message
news:Xn********************************@130.133.1. 4...
"Nel" <ne***@ne14.co.NOSPAMuk> wrote in news:DwGxc.12894$NK4.1841718
@stones.force9.net:
> Just looking for some general advice on modifying the URL for php.
>
> I am using .htaccess to allow a web site to translate example.html
> to index.php?content=example
> (below)
>
> ErrorDocument 404 http://www.example.com
> RewriteEngine on
> RewriteRule ^/?(.*).html$ /index.php?content=$1 [L]
>
> Is there any downside to using this method. I just want to know

before I
> roll it out over several other sites.
>
> Nel.
>


Nel,

I use something similar.
1) I redirect alias domains and domains without www. in front to my
main domain using a 301 redirect which is what Google likes in order
to maintain pagerank.
2) I test to make sure the page being requested is not a file or
directory that exists. If it exists, then retrive the existing page.
This is nice in case you want to have a pages that are not part of
your content management system.
3) I don't just redirect pages with .html extensions. I redirect
everything into content management system and then the cms parses the
requested page and strips extensions, trailing slashes, etc.

Options +SymlinksIfOwnerMatch

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.rootmode\.com
RewriteRule ^(.*)$ http://www\.rootmode\.com/$1 [R=
301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ $1 [L]

RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule ^(.*)$ /index.php?page=$1 [L]
--
Edward Alfert
http://www.rootmode.com/
Multiple Domain Hosting and Reseller Hosting Plans
Coupon Code (Recurring $5/month Discount): newsgroup


One of the reasons I am using .html is to give the site the look and
feel of a static html web site. I was under the impression, that with
some exceptions (like Google) search engines list the pages better
than index.php?content=example.
2) I test to make sure the page being requested is not a file or
directory that exists. If it exists, then retrive the existing page.
This is nice in case you want to have a pages that are not part of
your content management system.

If I need a stand alone page, it will probably have some php
requirement, so I would probably just call existing pages example.php.
I'm not likely to ever have static html files that could not be moved
over to content management.

Thanks for the detailed feedback. I had a look at your web site and
see what you mean. It works very well! :-)

Nel.


Nel,

The url is not rewritten to http://www.domain.tld/index.php?
content=example... it stays http://www.domain.tld/example so search
engines do not see that it is a dynamic site. They see a static url.

The site you looked at uses a differnt but similar technique that has
some drawbacks (like not being able to handle trailing slashes "/").
The code I listed is for the redesign I'm currently working on.

The code above is only the .htaccess portion, see the index.php page
that does other manipulation (not 100% done yet).

<?php
//========================================
//RootMode CMS - http://cms.rootmode.com/
//----------------------------------------

/*****************************************
Place the following in .htaccess in root directory
Make sure to modify domain in first RewriteCond and RewriteRule
******************************************
Options +SymlinksIfOwnerMatch

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.rootmode\.net
RewriteRule ^(.*)$ http://www\.rootmode\.net/$1 [R=
301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ $1 [L]

RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule ^(.*)$ /index.php?page=$1 [L]
*****************************************/

//========================================
//Set system/site specific variables
//----------------------------------------
$domain = $_SERVER["HTTP_HOST"]; //Can also set
manually to "www.domain.tld"
$path = "/var/www/html/"; //Absolute path is
preferred but relative will work
$dir_content = "content/";
$ext = ".php"; //Extension of
physical content files. Will not be displayed in address bar of
browser.
$page_default = "multiple-domain-hosting"; //No extension
$redirect_default = true; //true or false.
Useful for search engine optimization if set to true along with a
descriptive $page_default.
$page_404 = "sitemap"; //No extension
$dir_template = "template/";
$page_header = "header.php"; //Extension
required
$page_footer = "footer.php"; //Extension
required
$debug = true; //true or false

//========================================
//DO NOT MODIFY BELOW THIS LINE
//----------------------------------------

//========================================
//Send email if referred is a search engine
//----------------------------------------

//========================================
//Read requested page from mod_rewrite rule in .htaccess
//----------------------------------------
$page_content = $_REQUEST["page"];
if ($debug) { echo "(Test=User Requested Page):
page_content=".$page_content."<br />"; };

//========================================
//If no page was specified, retrieve default page
//----------------------------------------
if ((!$page_content) && ($redirect_default)) {
$page_redirect = $page_default;};
if ($debug) { echo "(Test=Redirect Default):
page_redirect=".$page_redirect."<br />"; };
if (!$page_content) { $page_content = $page_default; };
if ($debug) { echo "(Test=Default Page):
page_content=".$page_content."<br />"; };

//========================================
//If exists, remove trailing "/"
//Fix for search engines that append a "/" if the file being
requested does not have an extension
//Do not redirect to non-slash version because it might create a
loop
//----------------------------------------
if (substr($page_content,-1,1) == "/") { $page_content =
substr($page_content,0,-1); };
if ($debug) { echo "(Test=Trailing Slash):
page_content=".$page_content."<br />"; };

//========================================
//If exists, remove "." or ">"
//Fix for common problems of mangled links in emails
//----------------------------------------
$lastchar = substr($page_content, -1, 1);
if (($lastchar == '.') || ($lastchar == '>')) {
$page_redirect = substr($page_content, 0, -1); $page_content =
$page_redirect; };
if ($debug) { echo "(Test=Trailing . or >):
page_redirect=".$page_redirect."<br />"; };

//========================================
//If exists, remove extension
//----------------------------------------
//.htm, .php
if (substr($page_content,-4,1) == ".") {
$page_redirect = substr($page_content,0,-4); $page_content =
$page_redirect; };
//.html, .php3
if (substr($page_content,-5,1) == ".") {
$page_redirect = substr($page_content,0,-5); $page_content =
$page_redirect; };
//.shtml
if (substr($page_content,-6,1) == ".") {
$page_redirect = substr($page_content,0,-6); $page_content =
$page_redirect; };
if ($debug) { echo "(Test=Strip Extension): page_redirect=".
$page_redirect."<br />"; };

//========================================
//Force lower case for filename
//----------------------------------------
$page_content_lower = strtolower($page_content);
if ($page_content != $page_content_lower) { $page_redirect =
$page_content_lower; $page_content = $page_redirect; };
if ($debug) { echo "(Test=Lower Case):
page_redirect=".$page_redirect."<br />"; };

//========================================
//If requested page does not exist, then redirect to 404 page
//----------------------------------------
$file = $path.$dir_content.$page_content.$ext;
if ($debug) { echo "(Test=Physical Path): file=".
$file."<br />"; };
if (!file_exists($file)) { $page_redirect = $page_404; };
if ($debug) { echo "(Test=404): page_redirect=".
$page_redirect."<br />"; };

//========================================
//Determine which template (header and footer) to use
//----------------------------------------
if (!file_exists($path.$dir_content.$page_header)) {
$dir_header = $dir_content; } else { $dir_header = $dir_template; };
if ($debug) { echo "(Test=Header Path): dir_header=".
$dir_header."<br />"; };
if (!file_exists($path.$dir_content.$page_footer)) {
$dir_footer = $dir_content; } else { $dir_footer = $dir_template; };
if ($debug) { echo "(Test=Footer Path): dir_footer=".
$dir_footer."<br />"; };

//========================================
//Display content or do a 301 redirect to correct page
//----------------------------------------
if (!$page_redirect) {
include($path.$dir_header.$page_header);
include($path.$dir_content.$page_content.$ext);
include($path.$dir_footer.$page_footer);
} else {
header("Location: http://$domain/$page_redirect");
header("HTTP/1.0 301 Moved Permanently", true);
}

//========================================
//Helpful troubleshooting info
//----------------------------------------
if ($debug) { echo phpinfo(); };
//Uncomment next line to display phpinfo() even when not in
debug mode
//echo phpinfo();
?>

--
Edward Alfert
http://www.rootmode.com/
Multiple Domain Hosting and Reseller Hosting Plans
Coupon Code (Recurring $5/month Discount): newsgroup

Jul 17 '05 #7
"Nel" <ne***@ne14.co.NOSPAMuk> wrote in message
news:Lv*********************@stones.force9.net...
"Edward Alfert" <ea*****@rootmode.com> wrote in message
news:Xn********************************@130.133.1. 4...
"Nel" <ne***@ne14.co.NOSPAMuk> wrote in news:DwGxc.12894$NK4.1841718
@stones.force9.net:
Just looking for some general advice on modifying the URL for php.

I am using .htaccess to allow a web site to translate example.html to
index.php?content=example
(below)

ErrorDocument 404 http://www.example.com
RewriteEngine on
RewriteRule ^/?(.*).html$ /index.php?content=$1 [L]

Is there any downside to using this method. I just want to know before I
roll it out over several other sites.

Nel.


Nel,

I use something similar.
1) I redirect alias domains and domains without www. in front to my main
domain using a 301 redirect which is what Google likes in order to
maintain pagerank.
2) I test to make sure the page being requested is not a file or
directory that exists. If it exists, then retrive the existing page.
This is nice in case you want to have a pages that are not part of your
content management system.
3) I don't just redirect pages with .html extensions. I redirect
everything into content management system and then the cms parses the
requested page and strips extensions, trailing slashes, etc.

Options +SymlinksIfOwnerMatch

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.rootmode\.com
RewriteRule ^(.*)$ http://www\.rootmode\.com/$1 [R=
301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ $1 [L]

RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule ^(.*)$ /index.php?page=$1 [L]
--
Edward Alfert
http://www.rootmode.com/
Multiple Domain Hosting and Reseller Hosting Plans
Coupon Code (Recurring $5/month Discount): newsgroup


One of the reasons I am using .html is to give the site the look and feel

of a static html web site. I was under the impression, that with some
exceptions (like Google) search engines list the pages better than
index.php?content=example.


If you'd like to see a rather extensive use of rewrite to convert dynamic
URLs to apparently static URLs, you might want to visit www.nukecops.com and
take a look at the GoogleTap proposal that is fairly popular with phpNuke
users. I've looked at for educational purposes but have not chosen to use
it. It handles the re-write on incoming transactiosn and also rewrites
outbound html.

- Virgil
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: yawnmoth | last post by:
i'm trying to write a php script that will password protect some random directory by creating a .htaccess file, and a password file to accompany the .htaccess file, and it isn't working... ...
8
by: Joshua Beall | last post by:
Hi All, How do I disable magic quotes via .htaccess? I put the following file in my webroot, but it does not disable magic_quotes_gpc (according to phpinfo(), both the local and master value...
4
by: Ivo | last post by:
Greetings newsgroup, I am moving some php scripts to a new host. While getting to know the server, I ran into a strange problem. If I add a .htaccess file, or more specifically: a .htaccess with...
7
by: John | last post by:
Hello. I want to get this blasted .htaccess file sorted out, so I can have sessions without register_globals being on. I have looked everywhere for info on this and I mean everywhere...
0
by: Stoco | last post by:
I am trying to create a generic interface that will manage various ..htaccess protected directories. In the ideal world, the .htaccess would trigger a cgi script that would take login information...
4
by: Bill | last post by:
Does ASP have a file whose function is similar to .htaccess on Apache? I'm looking to protect subdirectory content.
0
by: Jack Hambabo | last post by:
Hi, I'm searching for a php script that can find out whether the current user (I know _SERVER will give me the name for non-cgi php) has the right to view a specific file. My dream is that I...
1
by: nickyeng | last post by:
I have checked this info from apache website, and i confused with it. Procteing System files it said: To run a really tight ship, you'll want to stop users from setting up .htaccess files...
0
by: asherwolf | last post by:
Hi, I'm trying to do something I think is pretty neat, but I've just about pulled my hair out by the behavior of my server. I'm hosting on GoDaddy, using a subdomain (www.mywebpage.com maps to...
2
by: jaanus | last post by:
Here we go... What I have been trying to do is to forward all http requests containing /cms/ to http://cms.mydomain.com/ example1: http://host1.mydomain.com/cms/init.php would be parsed from...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.