homepage Welcome to WebmasterWorld Guest from 23.22.97.26
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
redirect php to no extension, rewriterule for paging
how to redirect php to no extension. how to rewriterule for paging
luvvips




msg:4075353
 8:23 am on Feb 6, 2010 (gmt 0)

My web pages are with .php extension.
How to redirect php extensions to no extension?

My site web pages with .htm and .html extension, now I do not have .htm and .html pages anymore in my server.
But these .htm and .html pages have good ranking in search engines and still getting links from search engines. So, how can I use re-write permanently those .htm or .html links to new .php links.
I am also having review pages and paging of testimonials like:
domain.com/review.php?page=i-appreciate-all-your-help-for-usa-visa-of-wong
how to rewriterule?
domain.com/review/i-appreciate-all-your-help-for-usa-visa-of-wong

domain.com/testimonials.php?page=1
domain.com/testimonials.php?page=2
domain.com/testimonials.php?page=3
how to rewrite rule?
domain.com/testimonials/1
domain.com/testimonials/2
domain.com/testimonials/3

How to redirect php extensions to no extension?
How to RewriteRule for .htm or .html to no extension?
How to RewriteRule for paging?

 

jdMorgan




msg:4075416
 1:33 pm on Feb 6, 2010 (gmt 0)

This is a three-step process. The first two steps are required, and the last step is optional.

1) Change the links on your pages to remove the extensions from the URLs.

2) Internally rewrite extensionless URL requests and .htm and .html requests to add a .php file extension if those URLs will resolve to existing .php files when this extension is added.

3) Externally redirect direct client requests only for URLs with .php, .htm, and ,html extensions to remove the extension.

Jim

luvvips




msg:4075437
 2:59 pm on Feb 6, 2010 (gmt 0)

Hey Jim,
Thanks for your reply.
How about RewriteRule for paging?
As for as I understood about rewrite rule, could you please check the RewriteRule for all the processes.

RewriteEngine on
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) /$1.php [L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php\ HTTP
RewriteRule ^(.+)\.php$ /$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+html\ HTTP
RewriteRule ^([^.]+)\.html /$1.php [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+htm\ HTTP
RewriteRule ^([^.]+)\.htm /$1.php [R=301,L]

RewriteRule ^testimonials/([0-9]+)$ /testimonials/$1/ [R]
RewriteRule ^testimonials/([0-9]+)/$ /testimonials.php?page=$1

RewriteRule ^reviews/(.*)$ /reviews/$1/ [R]
RewriteRule ^reviews/(.*)/$ /reviews.php?page=$1

Please help me to check and let me know if it is correct.

Thanks!

jdMorgan




msg:4075444
 3:34 pm on Feb 6, 2010 (gmt 0)

We'll work on paging later -- one thing at a time, please.

You rules are not in the correct order, and your filepaths will therefore be exposed to clients as URLs if any redirect is invoked. Put all external redirects first, in order from most-specific to least-specific, followed by all internal rewrites, again in order from most- to least-specific. Take advantage of the power of regular expressions to eliminate redundant rules. Always specify a protocol and canonical domain in external redirects. Always use an "[L]" flag on every rule, unless you know why you should not do so for a specific rule. Never redirect to an "index page" filepath -- redirect to "/" instead.

RewriteEngine on
#
# Externally redirect direct client requests for index page filepaths to "/" URLs
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/\ ]+/)*index\.(php|html?)\ HTTP/
RewriteRule ^(([^/]+/)*)index\.(php|html?)$ http://www.example.com/$1 [R=301,L]
#
# Externally redirect direct client requests to remove file extensions from obsolete inbound links
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/\ ]+/)*([^.\ ]+\.)+(php|html?)\ HTTP
RewriteRule ^(([^/]+/)*[^.]+)\.(php|html?)$ http://www.example.com/$1 [R=301,L]
#
# Externally redirect testimonial and reviews URLs to append missing trailing slash
RewriteRule ^testimonials/([0-9]+)$ http://www.example.com/testimonials/$1/ [R=301,L]
RewriteRule ^reviews/(.+)$ http://www.example.com/reviews/$1/ [R=301,L]
#
# Externally redirect non-canonical hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
# Internally rewrite requests for testimonials and reviews URLs to php scripts
RewriteRule ^testimonials/([0-9]+)/$ /testimonials.php?page=$1 [L]
RewriteRule ^reviews/(.+)/$ /reviews.php?page=$1 [L]
#
# Internally rewrite URLs requested with no filetype to php scripts
# unless the requested URL resolves to an existing directory or file.
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /$1.php [L]

Jim

luvvips




msg:4076123
 4:42 am on Feb 8, 2010 (gmt 0)

Hello Jim,
Thanks again for your great help. I am new and learning how to re-write and re-direct. Thanks once again.
All external .html|.php links are set up with no extension as I wanted.
But some problem 's been created for my contact us page. When I am posting form data to email through php script. I am getting an error. Error: (All fields with no data)
../contact-us.php is my form and ../sendmail.php is my php script which sends the data to email. Is This because of no .php ?
And also Paging is not working fine in Internal rewrite
# Internally rewrite requests for testimonials and reviews URLs to php scripts
RewriteRule ^testimonials/([0-9]+)/$ /testimonials.php?page=$1 [L]
RewriteRule ^reviews/(.+)/$ /reviews.php?page=$1 [L]

I did mistake to write review page, it is review.php. So I changed accordingly.
RewriteRule ^testimonials/([0-9]+)/$ /testimonials.php?page=$1 [L]
RewriteRule ^review/(.+)/$ /review.php?page=$1 [L]

Thanks again!

jdMorgan




msg:4076940
 1:58 pm on Feb 9, 2010 (gmt 0)

Add an exclusion for sendmail.php to the second rule (the one that redirects to remove ".php" from URLs) :

RewriteCond %{REQUEST_URI} !^/sendmail\.php$

Regarding your "paging problem," please post several example URLs (as published as links on your pages) and then state what script filepath and query string is required for each of those URLs. Please use "example.com" if you need to state a domain name.

Jim

luvvips




msg:4076987
 3:14 pm on Feb 9, 2010 (gmt 0)

Thanks Jim,
Regarding paging problem please find some example urls below:
http://www.example.com/testimonials.php
http://www.example.com/testimonials.php?page=1
http://www.example.com/testimonials.php?page=2
http://www.example.com/testimonials.php?page=3
http://www.example.com/testimonials.php?page=4
... and so on

Review Pages
http://www.example.com/review.php?page=i-am-impressed-with-your-firms-services
http://www.example.com/review.php?page=you-did-all-of-legal-work-with-filling-leaving-me-free-to-continue
http://www.example.com/review.php?page=thank-you-for-all-you-have-done-for-us
http://www.example.com/review.php?page=i-would-like-to-say-what-a-great-job-you-did-securing-our-job
http://www.example.com/review.php?page=tanasa#*$!-got-her-green-card-We-could-not-do-it-without-you
http://www.example.com/review.php?page=thank-you-for-all-you-have-done-for-us
etc
Do you need more urls?
Thanks again

jdMorgan




msg:4076993
 3:29 pm on Feb 9, 2010 (gmt 0)

We need both the URLs *and* the filepaths to which those URLs are to resolve.

Jim

luvvips




msg:4077477
 8:17 am on Feb 10, 2010 (gmt 0)

Hey Jim,

Thanks once again for looking into my problem and I am highly appreciated to you to helping me ask the right question.

Here is filepaths within our server below:
http://www.example.com/testimonials.php
http://www.example.com/testimonials.php?page=1
http://www.example.com/testimonials.php?page=2
http://www.example.com/testimonials.php?page=3
http://www.example.com/testimonials.php?page=4
... and so on
Both testimonials.php and testimonials.php?page=1 filepath belongs to the same page, means value is same for both pages. When user click testimonials link they go to testimonials.php page and when they click on page 1 in all testimonial pages, they are going to filepath testimonials.php?page=1

RewriteRule line you suggest deal with this part of my URLs: How we can fix for testimonials and testimonials/1 pages
http://www.example.com/testimonials
or
http://www.example.com/testimonials/1
http://www.example.com/testimonials/2
http://www.example.com/testimonials/3
http://www.example.com/testimonials/4
etc...

Review Pages filepaths within our server below:
http://www.example.com/review.php?page=i-am-impressed-with-your-firms-services
http://www.example.com/review.php?page=you-did-all-of-legal-work-with-filling-leaving-me-free-to-continue
http://www.example.com/review.php?page=thank-you-for-all-you-have-done-for-us
http://www.example.com/review.php?page=i-would-like-to-say-what-a-great-job-you-did-securing-our-job
http://www.example.com/review.php?page=tanasa#*$!-got-her-green-card-We-could-not-do-it-without-you
http://www.example.com/review.php?page=thank-you-for-all-you-have-done-for-us
etc

RewriteRule line you suggest deal with this part of my URLs:
http://www.example.com/review/i-am-impressed-with-your-firms-services
http://www.example.com/review/you-did-all-of-legal-work-with-filling-leaving-me-free-to-continue
http://www.example.com/review/thank-you-for-all-you-have-done-for-us
http://www.example.com/review/i-would-like-to-say-what-a-great-job-you-did-securing-our-job
http://www.example.com/review/tanasa#*$!-got-her-green-card-We-could-not-do-it-without-you
http://www.example.com/review/thank-you-for-all-you-have-done-for-us
etc

It'll highly appreciating.

Regards,
luvvips

jdMorgan




msg:4077578
 1:08 pm on Feb 10, 2010 (gmt 0)

You are apparently confusing URLs with filepaths.

To save time, we need to see a "map". The form of the "map" corresponds with the form of the rules:

RewriteRule ^URL$ -> filepath
for example:
RewriteRule ^reviews/(.+)/$ /reviews.php?page=$1 [L]
here the URL requested by a client (e.g. browser) is example.com/reviews/<something>/ and the filepath to be used by the server to serve this request is /reviews.php?page=<something>

Jim

luvvips




msg:4079049
 2:31 pm on Feb 12, 2010 (gmt 0)

Hello Jim,
Thanks again. What kind of "map"? I did not get this.

Thanks!

g1smd




msg:4079333
 9:33 pm on Feb 12, 2010 (gmt 0)

What is the URL that the user requests, either by typing in a URL, or by clicking on a link containing a URL?

What is the filepath inside the server that is pointing to the script that will ultimately serve the content to the user?

luvvips




msg:4079528
 7:04 am on Feb 13, 2010 (gmt 0)

URL are generating by clicking on links which are generating dynamic URL from database.
<a href="http://www.example.com/review.php?page=' . $url . '">read more</a>
which are generating these filepaths below:
http://www.example.com/review.php?page=i-am-impressed-with-your-firms-services
http://www.example.com/review.php?page=you-did-all-of-legal-work-with-filling-leaving-me-free-to-continue
http://www.example.com/review.php?page=thank-you-for-all-you-have-done-for-us
http://www.example.com/review.php?page=i-would-like-to-say-what-a-great-job-you-did-securing-our-job
http://www.example.com/review.php?page=tanasana-got-her-green-card-We-could-not-do-it-without-you
http://www.example.com/review.php?page=thank-you-for-all-you-have-done-for-us

And RewriteRule line you suggest deal with this part of my URLs:
http://www.example.com/review/i-am-impressed-with-your-firms-services
http://www.example.com/review/you-did-all-of-legal-work-with-filling-leaving-me-free-to-continue
http://www.example.com/review/thank-you-for-all-you-have-done-for-us
http://www.example.com/review/i-would-like-to-say-what-a-great-job-you-did-securing-our-job
http://www.example.com/review/tanasana-got-her-green-card-We-could-not-do-it-without-you
http://www.example.com/review/thank-you-for-all-you-have-done-for-us

Thankx again

g1smd




msg:4080052
 4:08 pm on Feb 14, 2010 (gmt 0)

The first thing that needs to happen here is that you must alter your script so that the links produced on the pages look like href="/review/thank-you-for-all-you-have-done-for-us".

Only then can mod_rewrite do its job, which is to take that incoming request and translate it to get the real internal server location for the content.

Finally, you'll need to set up a redirect such that if an external request asks for the dynamic URL, that the user is redirected to make a new request for the new 'static' URL.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved