Forum Moderators: phranque
Htaccess files allow rewriting pages into whatever one wants. However, something is confusing to me.
Here is my htaccess
Options FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.html$ /my-page\.php?id=$1 [nc]
which makes my-page.php?id=my-page-title
become
my-page-title.html
My question is how will the search engines index the site. I am assuming the SEs will index as php? or html? I was just curious to know.
If the engines do index in php, then what is the point of the .htaccess file with regard to creating html extensions.
Any remarks or clarification on this topic would be appreciated.
Thank you
which makes which makes my-page.php?id=my-page-titlebecome
my-page-title.html
Actually, it does the reverse. It changes any request for my-page-title.html into a call to your script
at my-page.php?id=my-page-title
> If the engines do index in php, then what is the point of the .htaccess file with regard to creating html extensions.
The mod_rewrite code is half of the job. Change your php pages (using preg_replace) to output html page links. This is what the visitors and search engines will see. Then when they request an html page, your htaccess code will change the request back into a call to your script.
Jim
Actually, it does the reverse. It changes any request for my-page-title.html into a call to your script
at my-page.php?id=my-page-title
Thank you jdMorgan. What do I need to do then since what I am trying to do is make my php pages read as html pages. It seems like I accomplished the reverse of what I want to happen according to your post.
Also, when you say I should use the preg_replace function, could you tell me what you mean exactly and what it would help me accomplish? Do you have an example of preg_replace and its impact?
Do you have links to introduce the concept and use of preg_replace and what its purpose is?
Thank you for your feedback.
[mod_rewrite works *after* a (URL) request is received by the server, but *before* any content (file or script) is served. That is critical to understanding this sequence.]
All you are missing is the first step, and there's nothing wrong with what you coded. You just need to change the links on your PHP pages, too. (This technique is quite common: Note that all pages at WebmasterWorld are dynamically-generated, but look at those nice static URLs in your browser address bar!)
Jim
Is it better to code in order to generate the html pages through the help of a conversion software, if any?
Do you know of any program which helps you generate html pages from your MySQL db?
Thanks
if I enter this code in the page where I need to change the links:
$newhrefs = preg_replace("/home-furnishing.php\?addition2=(.*)/", "$1\.html", $hrefs);
would it accomplish what I want:
Example:
home-furnishing.php?addition2=my-title
would want to make it through preg_replace as:
my-title.html
I am doing it correctly. If not, what do I need to change and/or add?
Thanks.
I spent a while reading a tutorial which made sense and here is what I got as a result:
$str = preg_replace("/home-furnishing\.php\?addition2=(.*?)/", "$1\.html", $str);
this should make for example
home-furnishing.php?addition2=whatever-table-field-data-text
into
whatever-table-field-data-text.html
I really am getting annoyed as this is not accomplishing anything. Am I writing something wrong? (Obviously I seem to do so)
Things seem to make more sense now but still not clicking.:(
Here is my php code from the source:
<a href="home-furnishing.php?addition2=<?php echo $row_nav_menu['addition2'];?>
Therefore I added what you modified to my php code above the <head> tag on my php pages.
As you know, what I want to accomplish is have the value of 'addition2' to become some-page.html
Therefore the code preg_replace:
$str = preg_replace("/home-furnishing\.php\?addition2=(.+)/i", "$1.html", $str);
Maybe I am not using the right code but that is driving me crazy!
all I want is instead of having for example:
home-furnishing.php?addition2=some-page
I want to have
some-page.html (when I test in the browser, the links are still in php such as home-furnishing.php?addition2=some-page instead of some-page.html)
I am so close to being done, this preg_replace drives me crazy.
Thanks
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule index.php?ad=blah [mydomain.com[R=301,L]...]
since for whatever reason google is recognizing the index.php?ad=blah as our main site i want to permanently rewrite it to index.php. But this little tid bit above isn't working, not sure why? When i go to http...index.php?ad=blah it doesn't rewrite to index.php...
thanks.
// Instead of this...
<a href="home-furnishing.php?addition2=<?php echo $row_nav_menu['addition2'];
// ...try building the link prior to inserting into the html instead:
$str = 'home-furnishing.php?addition2=' . $row_nav_menu['addition2'];
$str = preg_replace("/home-furnishing\.php\?addition2=(.+)/i", "$1.html", $str);
?>
<a href="<?php echo $str;?>">
Only one problem, in my category links, the repeat region no longer works: in other words, the link is always the same, which is the one for the first value in my table. It does not pick up the rest of the values in order to link to the appropriate data/page.
Here is the modified code along with the code for the repeat region. I am guessing that I need to change some variable name somewhere in the code and have tried a few changes without success.
<?php do {?>
<a href="home-furnishing.php?addition2=<?php echo $row_nav_menu['addition2'];?>" class="main_menu"><?php echo $row_nav_menu['cat'];?></a><br>
<?php } while ($row_nav_menu = mysql_fetch_assoc($nav_menu));?>
Which creates in the browser the following issue:
<a href="All-About-Home-Furnishing.html" class="main_menu">All About Home Furnishing</a><br>
<a href="All-About-Home-Furnishing.html" class="main_menu">Bathroom Decorating</a><br>
<a href="All-About-Home-Furnishing.html" class="main_menu">Kitchen Design & Decorating</a><br>
<a href="All-About-Home-Furnishing.html" class="main_menu">Living Room Furniture</a>
<?php do {?>
<a href="<?php echo $str;?>" class="main_menu"><?php echo $row_nav_menu['cat'];?></a><br>
<?php } while ($row_nav_menu = mysql_fetch_assoc($nav_menu));?>
And I get the the above html links, all pointing to the same html page. However, in my table, each category name has a different link. Therefore I don't understand what is wrong.
This is what I added as told by Coopster to my php:
$str = 'home-furnishing.php?addition2=' . $row_nav_menu['addition2'];
$str = preg_replace("/home-furnishing\.php\?addition2=(.+)/i", "$1.html", $str);?>
The above updates work great as I said except that I get in the browser the links:
<a href="All-About-Home-Furnishing.html" class="main_menu">All About Home Furnishing</a><br>
<a href="All-About-Home-Furnishing.html" class="main_menu">Bathroom Decorating</a><br>
<a href="All-About-Home-Furnishing.html" class="main_menu">Kitchen Design & Decorating</a><br>
when I should get
<a href="All-About-Home-Furnishing.html" class="main_menu">All About Home Furnishing</a><br>
<a href="Bathroom-Decorating.html" class="main_menu">Bathroom Decorating</a><br>
<a href="Kitchen-Design &-Decorating.html" class="main_menu">Kitchen Design & Decorating</a><br>
This is my last issue before I can get it to work. I have tried a few changes without success.
Any help would be great
Thanks