Forum Moderators: phranque
In start sorry for my english because its not my home language ...
Ok I saw many of your post same to my problem but till now did not get any of the one fixed on my problem.
I have a web which is dynamically designed but now the prob is that when I want these dynamic URLs to be redirected to Static URLs becz I heard that google and othe search engines crawls static URLs more efficiently then dynamic.
I saw some of your post and made some of the code to do this
that is :
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)\.html$ $1 [L]
I try to use some conditions like RewriteCond %{the_request} but can not able to work on it and can not understand it also
I open a anyname.php page with anyname.html then it works but when I open anyname.php then it is not redirect it to anyname.html and I want to do it becz then google can crawl my ranking pages as static URLs and delete all of mine Dynamic URLs from its database....
So can you please help me Jim?
Thanks in advance
As for the URLs that users 'see' and 'use' on the web, those are defined by the URLs in the links on your pages.
If you are changing to new URLs, you need a redirect from the old format to the new format.
If the old format was "dynamic" then you also need a rewrite to connect the new URL requests with the old format internal server filepath.
.
RewriteRule ^(.*)\.html$ $1 [L] As coded, this takes a URL request for example.com/<something>.html and performs a rewrite such that the server looks for a file called /something (no extension) on the server to fulfill that request.
In this case, the code is exactly backwards if you intended to be using that for the rewrite; and that code likely does not do what you want for the internal filepath needing to have parameters within.
In this case, the code is incomplete if you intended that to be the redirect. The addition of the domain name to the target, and the [R=301,L] flag on the end, would start to get you in the right direction.
There was a question just yesterday covering the same issues, and listing all the steps you need to take.
I am just finding some so feel nice to talk you ... lets come to point
I have dynamic pages like this www.mysite.com/category/pagename.php
I want to is when user or GBOT goes to www.mysite.com/category/pagename.php then redirect to the page www.mysite.com/category/pagename.html
and only the way to visit a page it through a static URL like www.mysite.com/category/pagename.html
so can you please explain me I do my work till this query now
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)\.html$ $1 [L]
1) I want these dynamic URLs like www.example.com/category/pagename.php to be redirected to Static URLs
2) I open a anyname.php page with anyname.html
# Externally redirect direct client requests for /category/<pagename>.php
# to www.example.com/category/<pagename>.html
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /category/([^.]+)\.php[?]?[^\ ]*\ HTTP/
RewriteRule ^category/([^.]+)\.php$ http://www.example.com/$1.html? [R=301,L]
#
# Internally rewrite requests for /category/<pagename>.html to /category/<pagename>.php
RewriteRule ^category/([^.]+)\.html$ /category/$1.php$ [L]
As shown, this code applies to /category pages only, as stated in requirement #1. If you want it to apply to all pages, then remove "/category" from all lines.
See the thread Changing Dynamic URLs to Static URLs [webmasterworld.com] in our Apache Forum Library for a full description of this three-step process.
Jim
- use AddHandler to parse .html files for PHP scripts inside them - avoiding any need for redirects or rewrites at all.
Going extensionless (which would use the code above, except that the URL would NOT include .html on the end). The filenames on the server could be .html or .php, it wouldn't matter (but AddHandler would be needed if the files on the server were .html named).
Do any of your URLs use parameters? Those pass through your redirects and rewrites untouched in the code examples above.
Thanks for your reply
When I put these code I change my category name to funny like www.mysite.com/funny/pagename.php
but it does not work when I open a page www.mysite.com/funny/pagename.php it just opens, nor redirect to www.mysite.com/funny/pagename.html and neither works when I put the URL in browser tab like www.mysite.com/funny/pagename.html
Please give me what is happening here and what all this logic is please I be very thank full to you
Waiting for reply
I try to make one query my self:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)\.html$ $1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ (.+)\.php\ HTTP/
RewriteRule ^(.+)\.php$ /Copy%20of%20New%20Fun/$1\.html [R=301,L]
It do both of my work but not in effiecient manner mean that when opening anypage.php then redirect to anypage.html but I think there are some cautions in it mean that it will be dangerous to execute can you please let me know by checking this query that it is right or do some extra works
RewriteRule ^(.+)\.php$ /Copy\%20of\%20New\%20Fun/1$.html [NE,R=301,L]
As you've ignored my other suggested changes, I cannot comment further.
Jim
As for the rest of the code, it still has errors in it that you need to correct using Jim's instructions above.
List redirects before rewrites. Make sure the domain name is included in the redirect target. Comment your code.